如何在SQL Server 2008中查看事务日志

109*_*793 53 sql-server transaction-log

我需要在SQL Server 2008上查看数据库的事务日志,以便找到删除事务并希望将其回滚.

不幸的是,我不知道从哪里开始,我发现很难确定哪些是谷歌上的文章.

我该怎么办?

kev*_*ers 52

您可以使用未记录的

DBCC LOG(databasename, typeofoutput)
Run Code Online (Sandbox Code Playgroud)

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.
Run Code Online (Sandbox Code Playgroud)

例如,DBCC LOG(数据库,1)

你也可以尝试fn_dblog.

要使用事务日志回滚事务,我将使用事务日志查看Stack Overflow post Rollback事务.


小智 20

您无法轻松读取事务日志文件,因为没有正确记录.基本上有两种方法可以做到这一点.使用未记录或半文档化的数据库函数或使用第三方工具.

注意:这仅在数据库处于完全恢复模式时才有意义.

SQL函数:

DBCC LOG和fn_dblog - 这里这里有更多细节.

第三方工具:

Toad for SQL ServerApexSQL Log.

您还可以查看讨论过的其他几个主题:


vig*_*ity 5

我在错误的环境中意外删除了一大堆数据,这篇文章是我发现的第一篇文章之一.

因为我同时恐慌并寻找解决方案,所以我去看了第一件事--ApexSQL Logs,这是2000美元,这是一个可接受的成本.

但是,我发现Toad for Sql Server可以从事务日志生成撤消脚本,而且只需655美元.

最后,找到了一个更便宜的选项SysToolsGroup Log Analyzer,它只有300美元.