SQLcommitted

Committed with SQL

How to fetch last generated timestamp of a database?

Global variable @@DBTS  returns the last used timestamp value for the current database.

Its return type is varbinary.

When ever any record is inserted or updated a new timestamp gets generated and the new generated value can be fetched using @@DBTS.

Example:

Use Master

Go

Create DataBase SQLCommitted

Go

SELECT @@DBTS

Output1 : 0x0000000000000FA0

Now lets create a table ,insert a record into it and will compare the Col2 value with @@DBTS

Create Table T1( Col1 int, Col2 timestamp)

Go

Insert T1 (Col1) values (1)

Go

Select @@DBTS, Col2 from T1

Output2: 0x0000000000000FA1, 0x0000000000000FA1

In Output2 we can see both @@DBTS and Col2 returns same value.

About these ads

April 18, 2012 - Posted by | SQL Info

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 60 other followers

%d bloggers like this: