马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
使为了数据安全,我们搭建了主从。但实时主从备份只能防止硬件问题,比如主库的硬盘损坏。但对于误操作,则无能为力。比如在主库误删一张表,或者一个update语句没有指定where条件,导致全表被更新。数据
createprocspGenInsertSQL
@TableNameasvarchar(100)
as
--declare@TableNamevarchar(100)
--set@TableName=orders
--set@TableName=eeducation
DECLARExCursorCURSORFOR
SELECTname,xusertype
FROMsyscolumns
WHERE(id=OBJECT_ID(@TableName))
declare@F1varchar(100)
declare@F2integer
declare@SQLvarchar(8000)
set@sql=SELECTINSERTINTO+@TableName+VALUES(
OPENxCursor
FETCHxCursorinto@F1,@F2
WHILE@@FETCH_STATUS=0
BEGIN
set@sql=@sql+
+casewhen@F2IN(35,58,99,167,175,231,239,61)then+casewhen+@F1+ISNULLthenelseend+else+end
+replace(ISNULL(cast(+@F1+asvarchar),NULL),,)
+casewhen@F2IN(35,58,99,167,175,231,239,61)then+casewhen+@F1+ISNULLthenelseend+else+end
+char(13)+,
FETCHNEXTFROMxCursorinto@F1,@F2
END
CLOSExCursor
DEALLOCATExCursor
set@sql=left(@sql,len(@sql)-5)++)FROM+@TableName
print@sql
exec(@sql)
第二版:2003.03.08
alterprocSPGenInsertSQL(@tablenamevarchar(256))
as
begin
declare@sqlvarchar(8000)
declare@sqlValuesvarchar(8000)
set@sql=(
set@sqlValues=values(+
select@sqlValues=@sqlValues+cols++,+,@sql=@sql+[+name+],
from
(selectcase
whenxtypein(48,52,56,59,60,62,104,106,108,122,127)
thencasewhen+name+isnullthenNULLelse+cast(+name+asvarchar)+end
whenxtypein(58,61)
thencasewhen+name+isnullthenNULLelse+++cast(+name+asvarchar)+++end
whenxtypein(167)
thencasewhen+name+isnullthenNULLelse+++replace(+name+,,)+++end
whenxtypein(231)
thencasewhen+name+isnullthenNULLelse+N++replace(+name+,,)+++end
whenxtypein(175)
thencasewhen+name+isnullthenNULLelse+++cast(replace(+name+,,)asChar(+cast(lengthasvarchar)+))++end
whenxtypein(239)
thencasewhen+name+isnullthenNULLelse+N++cast(replace(+name+,,)asChar(+cast(lengthasvarchar)+))++end
elseNULL
endasCols,name
fromsyscolumns
whereid=object_id(@tablename)
)T
set@sql=selectINSERTINTO[+@tablename+]+left(@sql,len(@sql)-1)+)+left(@sqlValues,len(@sqlValues)-4)+)from+@tablename
--print@sql
exec(@sql)
end
第三版:2003.3.9
ALTERprocSPGenInsertSQL(@tablenamevarchar(256))
as
begin
declare@sqlvarchar(8000)
declare@sqlValuesvarchar(8000)
set@sql=(
set@sqlValues=values(+
select@sqlValues=@sqlValues+cols++,+,@sql=@sql+[+name+],
from
(selectcase
whenxtypein(48,52,56,59,60,62,104,106,108,122,127)
thencasewhen+name+isnullthenNULLelse+cast(+name+asvarchar)+end
whenxtypein(58,61)
thencasewhen+name+isnullthenNULLelse+++cast(+name+asvarchar)+++end
whenxtypein(167,175)
thencasewhen+name+isnullthenNULLelse+++replace(+name+,,)+++end
whenxtypein(231,239)
thencasewhen+name+isnullthenNULLelse+N++replace(+name+,,)+++end
elseNULL
endasCols,name
fromsyscolumns
whereid=object_id(@tablename)andautovalisnull
)T
set@sql=selectINSERTINTO[+@tablename+]+left(@sql,len(@sql)-1)+)+left(@sqlValues,len(@sqlValues)-4)+)from+@tablename
print@sql
exec(@sql)
/*
select*
fromsyscolumns
whereid=object_id(test)andautovalisnull
*/
end
刚安装好的MySql包含一个含空密码的root帐户和一个匿名帐户,这是很大的安全隐患,对于一些重要的应用我们应将安全性尽可能提高,在这里应把匿名帐户删除、root帐户设置密码 |