|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
因此,我们的第一个“米”,就是二进制日志binlog必须是rowbased的。在rowbase下,二进制日志binlog同时记录了更新前后的整行记录。拔出|存储历程
我找到了两个存储历程,能主动天生对一个数据表的拔出和更新的存储历程,如今贡献给人人!
拔出:
Createproceduresp_GenInsert
@TableNamevarchar(130),
@ProcedureNamevarchar(130)
as
setnocounton
declare@maxcolint,
@TableIDint
set@TableID=object_id(@TableName)
select@MaxCol=max(colorder)
fromsyscolumns
whereid=@TableID
selectCreateProcedure+rtrim(@ProcedureName)astype,0ascolorderinto#TempProc
union
selectconvert(char(35),@+syscolumns.name)
+rtrim(systypes.name)
+casewhenrtrim(systypes.name)in(binary,char,nchar,nvarchar,varbinary,varchar)then(+rtrim(convert(char(4),syscolumns.length))+)
whenrtrim(systypes.name)notin(binary,char,nchar,nvarchar,varbinary,varchar)then
end
+casewhencolorder<@maxcolthen,
whencolorder=@maxcolthen
end
astype,
colorder
fromsyscolumns
joinsystypesonsyscolumns.xtype=systypes.xtype
whereid=@TableIDandsystypes.namesysname
union
selectAS,@maxcol+1ascolorder
union
selectINSERTINTO+@TableName,@maxcol+2ascolorder
union
select(,@maxcol+3ascolorder
union
selectsyscolumns.name
+casewhencolorder<@maxcolthen,
whencolorder=@maxcolthen
end
astype,
colorder+@maxcol+3ascolorder
fromsyscolumns
joinsystypesonsyscolumns.xtype=systypes.xtype
whereid=@TableIDandsystypes.namesysname
union
select),(2*@maxcol)+4ascolorder
union
selectVALUES,(2*@maxcol)+5ascolorder
union
select(,(2*@maxcol)+6ascolorder
union
select@+syscolumns.name
+casewhencolorder<@maxcolthen,
whencolorder=@maxcolthen
end
astype,
colorder+(2*@maxcol+6)ascolorder
fromsyscolumns
joinsystypesonsyscolumns.xtype=systypes.xtype
whereid=@TableIDandsystypes.namesysname
union
select),(3*@maxcol)+7ascolorder
orderbycolorder
selecttypefrom#tempprocorderbycolorder
更新:
Createproceduresp_GenUpdate
@TableNamevarchar(130),
@PrimaryKeyvarchar(130),
@ProcedureNamevarchar(130)
as
setnocounton
declare@maxcolint,
@TableIDint
set@TableID=object_id(@TableName)
select@MaxCol=max(colorder)
fromsyscolumns
whereid=@TableID
selectCreateProcedure+rtrim(@ProcedureName)astype,0ascolorderinto#TempProc
union
selectconvert(char(35),@+syscolumns.name)
+rtrim(systypes.name)
+casewhenrtrim(systypes.name)in(binary,char,nchar,nvarchar,varbinary,varchar)then(+rtrim(convert(char(4),syscolumns.length))+)
whenrtrim(systypes.name)notin(binary,char,nchar,nvarchar,varbinary,varchar)then
end
+casewhencolorder<@maxcolthen,
whencolorder=@maxcolthen
end
astype,
colorder
fromsyscolumns
joinsystypesonsyscolumns.xtype=systypes.xtype
whereid=@TableIDandsystypes.namesysname
union
selectAS,@maxcol+1ascolorder
union
selectUPDATE+@TableName,@maxcol+2ascolorder
union
selectSET,@maxcol+3ascolorder
union
selectsyscolumns.name+=@+syscolumns.name
+casewhencolorder<@maxcolthen,
whencolorder=@maxcolthen
end
astype,
colorder+@maxcol+3ascolorder
fromsyscolumns
joinsystypesonsyscolumns.xtype=systypes.xtype
whereid=@TableIDandsyscolumns.name@PrimaryKeyandsystypes.namesysname
union
selectWHERE+@PrimaryKey+=@+@PrimaryKey,(2*@maxcol)+4ascolorder
orderbycolorder
selecttypefrom#tempprocorderbycolorder
droptable#tempproc
有了rowbase的binlog后,我们来分析一下怎么实现闪回。平时的DML无非三种操作,增删改,先说三种操作的日志格式。 |
|