SQL Server: Cannot insert an explicit value into a timestamp column

后端 未结 7 2015
无人及你
无人及你 2020-11-30 09:25

When using this statement

create table demo (
    ts timestamp
)

insert into demo select current_timestamp

I get the following error:

相关标签:
7条回答
  • 2020-11-30 10:20

    You can't insert the values into timestamp column explicitly. It is auto-generated. Do not use this column in your insert statement. Refer http://msdn.microsoft.com/en-us/library/ms182776(SQL.90).aspx for more details.

    You could use a datetime instead of a timestamp like this:

    create table demo (
        ts datetime
    )
    
    insert into demo select current_timestamp
    
    select ts from demo
    

    Returns:

    2014-04-04 09:20:01.153
    
    0 讨论(0)
提交回复
热议问题