怎么在SQL中保存默认的时间戳?

解决方案 »

  1.   

    我是问你想做什么用。如果是随便默认一个,用cast(getdate() as timestamp)就可以
      

  2.   

    CREATE TABLE ExampleTable (PriKey int PRIMARY KEY, timestamp);insert into ExampleTable(PriKey )  select 1這個計數器是資料庫時間戳記
      

  3.   

    当前时间戳:
    select @@dbts
      

  4.   

    怎么不对呢:
    --联机丛书中如是说:
    --@@DBTS 返回当前数据库最后使用的时间戳值。插入或更新包含 timestamp 列的行时,将产生一个新的时间戳值。
    select @@DBTS
    go
    create table tb(id int,ts timestamp)
    insert into tb(id) select 1
    go
    select @@DBTS 
    insert into tb(id) select 1
    go
    select @@DBTS 
    go
    drop table tb
    /*
    ------------------
    0x00000000000007D3(1 行受影响)
    (1 行受影响)------------------
    0x00000000000007D4(1 行受影响)(1 行受影响)
    ------------------
    0x00000000000007D5(1 行受影响)*/
      

  5.   

    你可以这样来保存时间戳:
    declare @t timestamp
    set @t=0x00000000000007D8
      

  6.   

    为什么SQL SERVER里面的时间戳和MYSQL里面的不同呢?
      

  7.   

    你新建表的时候,给字段类型为【timestamp】类型就可以了SET ANSI_NULLS ON
    GOSET QUOTED_IDENTIFIER ON
    GOCREATE TABLE [dbo].[Table_1](
    [timestamp] [timestamp] NULL
    ) ON [PRIMARY]GO