Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Is there a way to tell if a row has been udpated?

Author  Topic 

lanejc
Starting Member

11 Posts

Posted - 2002-04-18 : 11:02:16
Is there any way to determine if a row has been updated since a certain time? I know I could add a column to check for this, but before I did that I wanted to make sure that there was no built-in way to do this.

Nazim
A custom title

1408 Posts

Posted - 2002-04-18 : 11:19:01
AFAIK therez no inbuilt way . if you have Audit tables , you can check from it OR you can install log explorer of lumingent to track the updates.




--------------------------------------------------------------


Edited by - Nazim on 04/18/2002 11:29:54
Go to Top of Page

VyasKN
SQL Server MVP & SQLTeam MVY

313 Posts

Posted - 2002-04-18 : 11:23:24
You can have a timestamp column in your table, for determining this.

Here's an example. First create a table with this structure and insert a row:

CREATE TABLE Tbl (i int, j int, k timestamp)

INSERT INTO Tbl (i, j) SELECT 1, 2

Now, run the following:

DECLARE @i int, @j int, @k varbinary(8)

SELECT @i = i, @j = j, @k = k
FROM Tbl

WAITFOR DELAY '00:00:30' --Open another connection and update the row

UPDATE Tbl SET j = 3 WHERE i = @i AND k = @k
IF @@ROWCOUNT > 0 PRINT 'Row updated' ELSE PRINT 'Row not updated, as it changed, since last viewed'

The above query will update the row, if it's not modified, since last read. It will fail to update the row, if you quickly open another window and update the row. Note that the WAITFOR DELAY command will wait for 30 seconds.

Idea behind using timestamp column is that, the timestamp vlaue of each row gets updated, whenever the row is updated.

--
HTH,
Vyas
Check out my SQL Server site @
http://vyaskn.tripod.com
Go to Top of Page
   

- Advertisement -