开发者

how to determine that my table was updated in sql server

I have a table in sql server 2005. Yesterday an update was performed on the table and then updated back to the origional record.

Now i want to figure out what t开发者_高级运维he updated values was. At least i want to learn if it was really updated or not.

Is there someway to determine what i want from the transaction logs?

Thanks.


There is an undocumented command:

DBCC log ( dbname, 0|1|2|3|4 )

where

0: minimum information (Default)

1: Returns info available using 0 + flags, tags and the log record length.

2: Returns info available using 1 + object, index, page ID and slot ID.

3: Maximum information about each operation.

4: Maximum information about each operation + hexadecimal dump of the current transaction log row

And read this: Looking for a SQL Transaction Log file viewer


Although is not a precise method (ex. you have data only from the last SQL Server restart), you can try to use sys.dm_exec_query_stats view:

CREATE TABLE dbo.LongTableName (ID INT IDENTITY(1,1) PRIMARY KEY, Column1 VARCHAR(10) NOT NULL);

INSERT LongTableName VALUES ('A');
INSERT LongTableName VALUES ('BB');
INSERT LongTableName VALUES ('CCC');
WAITFOR DELAY '00:00:05';
INSERT LongTableName VALUES ('DDDD');
GO

SELECT  ca.[text], s.last_execution_time, s.last_logical_reads, s.last_logical_writes, s.execution_count 
FROM    sys.dm_exec_query_stats s
CROSS APPLY sys.dm_exec_sql_text(s.sql_handle) ca
WHERE   ca.[text] LIKE '%INSERT%LongTableName%'
GO

DROP TABLE LongTableName;
GO

For example, one of the records will be:

text    last_execution_time     last_logical_reads  last_logical_writes execution_count
(@1 varchar(8000))INSERT INTO [LongTableName] values(@1)    
        2011-10-04 10:51:17.070 2                   0                   4
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜