Timestamp as part of composite primary key?

2019-08-21 19:26发布

I get this error when using linq-to-sql with timestamp as part of a composite primary key:

"The primary key column of type 'Timestamp' cannot be generated by the server."

I'm guessing this may be due to the fact timestamp is just a row version thus perhaps it must be created after the insert? Or...

2条回答
戒情不戒烟
2楼-- · 2019-08-21 19:43

You can work around it.. set

  • Auto Generated Value to True
  • Auto-Sync to OnInsert

...unless you already have of course

查看更多
不美不萌又怎样
3楼-- · 2019-08-21 19:43

don't use the timestamp data type!!

The timestamp syntax is deprecated. This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.

timestamp (Transact-SQL) http://msdn.microsoft.com/en-us/library/ms182776(SQL.90).aspx rowversion (Transact-SQL) http://msdn.microsoft.com/en-us/library/ms182776.aspx

Also, if it primarily designed to change, to keep track of versions, why make it a part of a primary key? changing a primary key can cause many problems!

If you need a system generated value for a primary key, use an identity or guid.

IDENTITY (Property) http://msdn.microsoft.com/en-us/library/aa933196(SQL.80).aspx
GUID uniqueidentifier http://msdn.microsoft.com/en-us/library/aa260656(v=SQL.80).aspx

查看更多
登录 后发表回答