如何插入时间戳?在sqlcommand(.net)中 [英] how insert timestamp ? in sqlcommand(.net)

查看:73
本文介绍了如何插入时间戳?在sqlcommand(.net)中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试向列timestamp插入一个值为Datetime.now

但是我得到了sql异常:

i try to insert to column "timestamp" a value as "Datetime.now"
but i got sql exception :

Cannot insert an explicit value into a timestamp column. Use INSERT with a column list to exclude the timestamp column, or insert a DEFAULT into the timestamp column.



请帮助


please help

推荐答案

只需添加有关时间戳字段的更多信息:



Just add more information about timestamp field:

Quote:

一个表只能有一个时间戳列。每次插入或更新包含时间戳列的行时,都会更新timestamp列中的值。此属性使时间戳列成为键的不良候选者,尤其是主键。对该行进行的任何更新都会更改时间戳值,从而更改键值。如果列位于主键中,则旧键值不再有效,并且引用旧值的外键不再有效。如果在动态游标中引用该表,则所有更新都会更改游标中行的位置。如果列在索引键中,则对数据行的所有更新也会生成索引的更新。

A table can have only one timestamp column. The value in the timestamp column is updated every time a row containing a timestamp column is inserted or updated. This property makes a timestamp column a poor candidate for keys, especially primary keys. Any update made to the row changes the timestamp value, thereby changing the key value. If the column is in a primary key, the old key value is no longer valid, and foreign keys referencing the old value are no longer valid. If the table is referenced in a dynamic cursor, all updates change the position of the rows in the cursor. If the column is in an index key, all updates to the data row also generate updates of the index.





了解更多:

http://technet.microsoft.com/en-us /library/aa260631%28v=sql.80%29.aspx [ ^ ]


您无法显式地将值插入时间戳列。它是自动生成的。不要在insert语句中使用此列。如果要手动管理列,请将其数据类型更改为datetime。要了解有关时间戳的更多信息,请访问 http://msdn.microsoft.com/en-us /library/ms182776(SQL.90).aspx [ ^ ]。 Microsoft建议不要使用时间戳。
You can't insert the values into timestamp column explicitly. It is auto-generated. Don't use this column in your insert statement. If you want to manually manage your column then change its datatype to datetime. To know more about timestamp visit http://msdn.microsoft.com/en-us/library/ms182776(SQL.90).aspx[^]. Microsoft does not recommend using timestamp.


这篇关于如何插入时间戳?在sqlcommand(.net)中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆