SQL Server/T-SQL Tutorial/Data Types/timestamp

Материал из SQL эксперт
Перейти к: навигация, поиск

Convert timestamp to int

   <source lang="sql">

2> CREATE TABLE T ( 3> int1 int, 4> bit1 bit NOT NULL DEFAULT 0, 5> rvr1 timestamp, 6> usr1 nvarchar(128) DEFAULT USER, 7> createtime datetime DEFAULT CURRENT_TIMESTAMP 8> ) 9> GO 1> 2> INSERT T (int1, bit1) VALUES (3, 1) 3> GO (1 rows affected) 1> SELECT int1, bit1, usr1, 2> CONVERT(int, rvr1) "Timestamp as int", 3> createtime 4> FROM T 5> GO int1 bit1 usr1 Timestamp as int createtime


---- -------------------------------------------------------------------------------------------------------------------------------- ---------------- -----------------------
         3    1 dbo                                                                                                                                          4005 2008-08-17 13:12:03.663

(1 rows affected) 1> drop table t; 2> GO 1></source>


timestamp type column

   <source lang="sql">

4> CREATE TABLE T ( 5> int1 int, 6> bit1 bit NOT NULL DEFAULT 0, 7> rvr1 timestamp, 8> usr1 nvarchar(128) DEFAULT USER, 9> createtime datetime DEFAULT CURRENT_TIMESTAMP 10> ) 11> GO 1> 2> INSERT T (int1, bit1) VALUES (3, 1) 3> GO (1 rows affected) 1> SELECT int1, bit1, usr1, 2> CONVERT(int, rvr1) "Timestamp as int", 3> createtime 4> FROM T 5> GO int1 bit1 usr1 Timestamp as int createtime


---- -------------------------------------------------------------------------------------------------------------------------------- ---------------- -----------------------
         3    1 dbo                                                                                                                                          4007 2008-08-17 13:12:04.477

(1 rows affected) 1> drop table t; 2> GO 1> 2></source>