Uniqueidentifier as Identity in SQL Server CE?

半城伤御伤魂 提交于 2019-12-11 07:54:43

问题


In SQL Server CE can I create an identity column with data type uniqueidentifier? If so, how? If not, why not?

I have tried creating it with "New Table"from the Server Explorer in VS2010, and the Identity option only gets enabled when the type is int.

Edit:

According to EricEJ's suggestion I did make the column PK. I also set it to be a "RowGuid"

   CREATE TABLE [MyTable] (
      [Id] uniqueidentifier ROWGUIDCOL 
      ...

I don't know exactly the intended purpose of the RowGuid property, but it seem to have the desired effect, namely to automatically create new default guid-values upon insert, without having to create them in code. It would be nice to have the default values to be sequential guids, but this doesn't seem to be supported by SQL Server CE.


回答1:


The only supported type for IDENTITY is int or bigint. But you can have a Guid/uniqueidentifier as primary key, and set a value of this in code using Guid.NewGuid().



来源:https://stackoverflow.com/questions/8763609/uniqueidentifier-as-identity-in-sql-server-ce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!