ApexSQL Log中的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,如下所示,你会发现它们是一致的
ApexSQL Log中的Redo Script跟原始SQL不一致问题的更多相关文章
- 说说MySQL中的Redo log Undo log都在干啥
在数据库系统中,既有存放数据的文件,也有存放日志的文件.日志在内存中也是有缓存Log buffer,也有磁盘文件log file,本文主要描述存放日志的文件. MySQL中的日志文件, ...
- 【转】说说MySQL中的Redo log Undo log都在干啥
阅读目录(Content) 1 undo 1.1 undo是啥 1.2 undo参数 1.3 undo空间管理 2 redo 2.1 redo是啥 2.2 redo 参数 2.3 redo 空间管理 ...
- MySQL中的redo log和undo log
MySQL中的redo log和undo log MySQL日志系统中最重要的日志为重做日志redo log和归档日志bin log,后者为MySQL Server层的日志,前者为InnoDB存储引擎 ...
- ApexSql Log 数据库操作的后悔药
ApexSQL Log破解版是一款功能强大的SQL数据恢复工具,支持SQL2005/2008/2012.很多时候我们存放在服务器中的SQL数据库会因黑客破坏或误操作造成数据库文件丢失的你问题,当数据库 ...
- ApexSQL Log 从意外UPDATE和DELETE操作中恢复SQL Server数据
下载地址:https://www.apexsql.com/download.aspx 如何从意外UPDATE和DELETE操作中恢复SQL Server数据 ApexSQL Log 从意外UPDATE ...
- MySQL中的 redo 日志文件
MySQL中的 redo 日志文件 MySQL中有三种日志文件,redo log.bin log.undo log.redo log 是 存储引擎层(innodb)生成的日志,主要为了保证数据的可靠性 ...
- gradle中的build script详解
目录 简介 project和task 一个例子 task详细讲解 task脚本 task依赖 动态task 默认task build script的外部依赖 gradle中的build script详 ...
- 从log中分析Android wif连接状态的方法
1.这里是从log中通过搜索关键字wpa_supplicant: wlan0: State过滤之后的log: Line 1: 11-25 20:10:14.968120 1104 1104 D w ...
- ApexSql Log 2014.04.1133破解版&补丁
已上传最新的2016版本,请移步: http://www.cnblogs.com/gsyifan/p/ApexSql_Log_2016_Crack.html 状态不好,鬼使补差的跑到服务器上updat ...
随机推荐
- Nginx的一些优化(突破十万并发)
Nginx的一些优化(突破十万并发) nginx指令中的优化(配置文件) worker_processes 8; nginx进程数,建议按照cpu数目来指定,一般为它的倍数. worker_cpu_a ...
- 虚拟机中的Linux安装VMware Tools
虚拟机中的Linux安装VMware Tools Tools" TITLE="虚拟机中的Linux安装VMware Tools" /> Tools" TI ...
- 20.Consent Controller Get请求逻辑实现
在这里之前讲的这一块的信息就要登场了 需要通过构造函数把这几个注入进来 县引入这三个命名空间 把这三个注入进来,这就是显示依赖 先通过returnUrl拿到这个Request request拿到后,就 ...
- IDEA上使用github上传代码
这里的origin是表示我创建一个名为origin的仓库吗? 早已经存在了,我该怎么删除这个wenda呢? 将它修改为wenda1,如下: 点击项目,右击: 再点击项目,右击,选择commit: 问题 ...
- php array数组(第一部分)
创建一个数组 <?php $arr = array("My","name","is","zhangsan"); e ...
- c# sleep 例子-线程挂起
using System; using System.Threading; public class arr { public static void Main() { //int[] arr; // ...
- POJ - 2533 Longest Ordered Subsequence与HDU - 1257 最少拦截系统 DP+贪心(最长上升子序列及最少序列个数)(LIS)
Longest Ordered Subsequence A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let ...
- codeforces1009G Allowed Letters【贪心+hall定理】
因为是字典序所以贪心选当前能选的最小的,所以问题就在于怎么快速计算当前这个位置能不能选枚举的字母 重排之后的序列是可以和原序列完美匹配的,而完美匹配需要满足hall定理,也就是左边任意k个集合一定和右 ...
- 洛谷P1722 矩阵 II(Catalan数)
P1722 矩阵 II 题目背景 usqwedf 改编系列题. 题目描述 如果你在百忙之中抽空看题,请自动跳到第六行. 众所周知,在中国古代算筹中,红为正,黑为负…… 给定一个1*(2n)的矩阵(us ...
- 2014-9-13 NOIP模拟赛
NOIP2014模拟赛 ——lwher 题目名 环上的游戏 舞蹈课 数位和乘积 源文件 cycle.cpp/c/pas dancingLessons.pas/cpp digit.cpp.cpp/c/p ...