SqlServer的timestamp數(shù)據(jù)類型

字號(hào):

--時(shí)間戳類型和bigint互相轉(zhuǎn)化示例:
    set nocount on
    --申明3個(gè)時(shí)間戳
    declare @timeFlag1 bigint
    declare @timeFlag2 bigint
    declare @timeFlag3 bigint
    --建立表,timestamp類型不需要字段名
    create table test(timestamp,a int)
    --插入1 記錄時(shí)間戳,@@dbts為數(shù)據(jù)庫時(shí)間戳
    insert into test select null,1
    set @timeFlag1=cast(@@dbts as bigint)
    --插入2 記錄時(shí)間戳
    insert into test select null,2
    set @timeFlag2=cast(@@dbts as bigint)
    --更新3 記錄時(shí)間戳
    update test set a=3 where a=2
    set @timeFlag3=cast(@@dbts as bigint)
    --時(shí)間戳1的記錄
    select *from test where timestamp=cast(@timeFlag1 as varbinary(8))
    --時(shí)間戳2的記錄已經(jīng)不存在了
    select *from test where timestamp=cast(@timeFlag2 as varbinary(8))
    --時(shí)間戳3的記錄
    select *from test where timestamp=cast(@timeFlag3 as varbinary(8))
    --刪除表
    drop table test
    set nocount off
    /**//*--測(cè)試結(jié)果
    timestamp     a
    0x000000000000B553 1
    timestamp     a
    timestamp     a
    0x000000000000B555 3
    */