Search This Blog

Tuesday, July 24, 2012

timestamp (Transact-SQL)

SQL Server > Data types > TimeStamp

Timestamp in SQL Server is a data type that exposes automatically generated, unique binary numbers within a database.

  • is generally used as a mechanism for version-stamping table rows. 
  • the storage size is 8 bytes. 
  • the timestamp data type is just an increment number and does not preserve a date or a time. 
  • to record a date or time, use a datetime data type.


Example

IF OBJECT_ID(N'tbl1', N'U') IS NOT NULL
       DROP TABLE tbl1;
GO

CREATE TABLE tbl1
(
       id     int,
       code   timestamp
);
GO

INSERT INTO tbl1(id) values  (1)
SELECT
       *
FROM
       tbl1

Result:

id code
1  0x00000000005C0E69