使用SQL语句查看SQL Server事务日志的方法


  本文标签:SQL 语句

  如果需要查看SQL Server 数据库中的事务日志,有什么方法呢?下面将为您介绍使用用sql语句dbcc log查看的方法,供您参考,希望对您有所启迪  。

  1)用系统函数

  SELECT allocunitname,operation,[RowLog Contents 0] as r0,[RowLog Contents 1] as r1FROM::Fn_dblog(null,null)where allocunitname likedbo.TArea%and operation in(LOP_INSERT_ROWS,LOP_DELETE_ROWS)
 
2)用DBCC

  DBCC log(hrdb, TYPE=2)
 
dbcc log(dbname,4)       --(n=0,1,2,3,4)

  1 - 更多信息plus flags, tags, row length

  2 - 非常详细的信息plus object name, index name,page id, slot id

  3 - 每种操作的全部信息

  4 - 每种操作的全部信息加上该事务的16进制信息

  默认 type = 0