我需要查看SQL Server 2008上数据库的事务日志,以便找到删除事务并希望将其回滚。
不幸的是,我不知道从哪里开始,而且我发现很难确定哪些是Google 上的好文章。
我应该怎么办?
您可以使用未记录的
DBCC LOG(databasename, typeofoutput)
其中类型输出:
0: Return only the minimum of information for each operation -- the operation, its context and the transaction ID. (Default)
1: As 0, but also retrieve any flags and the log record length.
2: As 1, but also retrieve the object name, index name, page ID and slot ID.
3: Full informational dump of each operation.
4: As 3 but includes a hex dump of the current transaction log row.
例如,DBCC LOG(database, 1)
你也可以试试 fn_dblog。
对于使用事务日志回滚事务,我会看看 Stack Overflow post Rollback transaction using transaction log。
您无法轻松读取事务日志文件,因为它没有正确记录。基本上有两种方法可以做到这一点。使用未记录或半记录的数据库功能或使用第三方工具。
注意:这仅在您的数据库处于完全恢复模式时才有意义。
SQL 函数:
DBCC LOG 和 fn_dblog - 更多细节在这里和这里。
第三方工具:
Toad for SQL Server和ApexSQL 日志。
您还可以查看讨论过的其他几个主题:
我不小心在错误的环境中删除了一大堆数据,而这篇文章是我发现的第一个。
因为我在恐慌和寻找解决方案的同时,我选择了我看到的第一件事 - ApexSQL Logs,它是 2000 美元,这是可以接受的成本。
但是,我后来发现Toad for Sql Server可以从事务日志中生成撤消脚本,而且价格仅为 655 美元。
最后,找到了一个更便宜的选项SysToolsGroup 日志分析器,它只有 300 美元。