内容简介:然后我们用ApexSQL Log挖掘事务日志,你会看到有很多对应的Delete记录,而且对应的Redo Script跟原始SQL是不一样的。如下所示,
最近遇到一个误更新数据的问题,使用ApexSQL Log做挖掘事务日志的时候,发现ApexSQL Log生成的Redo Script跟原始 SQL 是有 区别 的。 它们并不是完全一致的 。只是逻辑上等价而已。如下所示,我们做一个测试,如下所示,创建一个表后,并模拟忘记添加条件,出现误删除数据的情况
SELECT * INTO KERRY_TEST FROM SYS.OBJECTS; DELETE FROM KERRY_TEST
然后我们用ApexSQL Log挖掘事务日志,你会看到有很多对应的Delete记录,而且对应的Redo Script跟原始SQL是不一样的。如下所示,
下面是其中两个Redo Script(为了方便查看,对脚本进行了格式化)
--DELETE (0003F73C:000065FC:000D) done at 2019-06-13 10:35:56.876 by xxx\xxxx in transaction 0000:0ADF73EA (Committed) BEGIN TRANSACTION; DELETE FROM [dbo].[KERRY_TEST] WHERE /*** WARNING: WHERE CLAUSE FOR THIS STATEMENT WAS GENERATED FOR A TABLE WITH NO PRIMARY KEY AND NO CLUSTERED INDEX ***/ [name] = N'sysfgfrag' COLLATE Chinese_PRC_CI_AS AND [object_id] = 19 AND [principal_id] IS NULL AND [schema_id] = 4 AND [parent_object_id] = 0 AND [type] = N'S ' COLLATE Latin1_General_CI_AS_KS_WS AND [type_desc] = N'SYSTEM_TABLE' COLLATE Latin1_General_CI_AS_KS_WS AND [create_date] = '20160101 10:46:55.060' AND [modify_date] = '20160101 10:46:55.100' AND [is_ms_shipped] = 1 AND [is_published] = 0 AND [is_schema_published] = 0; IF @@ROWCOUNT <= 1 COMMIT TRANSACTION; ELSE BEGIN ROLLBACK TRANSACTION; PRINT 'ERROR: STATEMENT AFFECTED MORE THAN ONE ROW. ALL THE CHANGES WERE ROLLED BACK.'; END; --DELETE (0003F73C:000065FC:000A) done at 2019-06-13 10:35:56.876 by xxx\xxx in transaction 0000:0ADF73EA (Committed) BEGIN TRANSACTION; DELETE FROM [dbo].[KERRY_TEST] WHERE /*** WARNING: WHERE CLAUSE FOR THIS STATEMENT WAS GENERATED FOR A TABLE WITH NO PRIMARY KEY AND NO CLUSTERED INDEX ***/ [name] = N'sysseobjvalues' COLLATE Chinese_PRC_CI_AS AND [object_id] = 9 AND [principal_id] IS NULL AND [schema_id] = 4 AND [parent_object_id] = 0 AND [type] = N'S ' COLLATE Latin1_General_CI_AS_KS_WS AND [type_desc] = N'SYSTEM_TABLE' COLLATE Latin1_General_CI_AS_KS_WS AND [create_date] = '20160101 10:47:02.050' AND [modify_date] = '20160101 10:47:02.057' AND [is_ms_shipped] = 1 AND [is_published] = 0 AND [is_schema_published] = 0; IF @@ROWCOUNT <= 1 COMMIT TRANSACTION; ELSE BEGIN ROLLBACK TRANSACTION; PRINT 'ERROR: STATEMENT AFFECTED MORE THAN ONE ROW. ALL THE CHANGES WERE ROLLED BACK.'; END;
如果有聚集索引,你会看到没有WHERE条件的UPDATE、DELETE操作都会生成很多个对应的Redo Script,对应的WHERE条件则是聚集索引字段。如下测试所示:
SELECT * INTO KERRY_TEST2 FROM sys.objects; CREATE CLUSTERED INDEX PK_KERRY_TEST2 ON KERRY_TEST2(OBJECT_ID); UPDATE KERRY_TEST2 SET NAME = 'KERRY'; DELETE FROM KERRY_TEST2;
下面是对应的UPDATE、DELETE操作的redo script
--UPDATE (0003F73C:0000700A:001F) done at 2019-06-13 11:27:26.036 by xxx\xxx in transaction 0000:0ADF7404 (Committed) BEGIN TRANSACTION; UPDATE [dbo].[KERRY_TEST2] SET [name] = N'KERRY' COLLATE Chinese_PRC_CI_AS WHERE [object_id] = 3; IF @@ROWCOUNT <= 1 COMMIT TRANSACTION; ELSE BEGIN ROLLBACK TRANSACTION; PRINT 'ERROR: STATEMENT AFFECTED MORE THAN ONE ROW. ALL THE CHANGES WERE ROLLED BACK.'; END; -- DELETE (0003F73C:00007482:00D9) done at 2019-06-13 11:27:35.406 by xxx\xxx in transaction 0000:0ADF7405 (Committed) BEGIN TRANSACTION; DELETE FROM [dbo].[KERRY_TEST2] WHERE [object_id] = 836302139; IF @@ROWCOUNT <= 1 COMMIT TRANSACTION; ELSE BEGIN ROLLBACK TRANSACTION; PRINT 'ERROR: STATEMENT AFFECTED MORE THAN ONE ROW. ALL THE CHANGES WERE ROLLED BACK.'; END;
这里只是简单记录一下这个事情,千万不要以为Redo Script跟原始SQL是完全一致的。如果遇到这种问题,如何判断呢?可以查看Transaction ID,以及对应的Begin Time , End Time,如下所示,你会发现它们是一致的
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- acme.sh 续期问题(路径问题)
- 缓存的一些问题和一些加密算法【缓存问题】
- 如何把设计问题转化为数学问题(方法论)
- 推荐系统中的冷启动问题和探索利用问题
- GraphQL 教程(六)—— N+1问题和缓存等问题
- Golang 并发问题(四)之单核上的并发问题
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
计算机图形学与几何造型导论
戈德曼 / 邓建松 / 2011-9 / 69.00元
《世界著名计算机教材精选:计算机图形学与几何造型导论》是世界著名计算机教材精选之一。《世界著名计算机教材精选:计算机图形学与几何造型导论》共四部分三十章节,内容包括乌龟绘图,应用递归乌龟程序生成分形,分形的奇特性质,仿射变换,仿射几何:二维计算机图形学的连点过程,应用迭代函数系统生成分形,不动点定理及其推论,递归乌龟程序与共形迭代函数系统等。《世界著名计算机教材精选:计算机图形学与几何造型导论》可......一起来看看 《计算机图形学与几何造型导论》 这本书的介绍吧!