唯一标识符作为 SQL Server CE 中的标识? [英] Uniqueidentifier as Identity in SQL Server CE?

查看:45
本文介绍了唯一标识符作为 SQL Server CE 中的标识?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 SQL Server CE 中,我可以创建一个数据类型为 uniqueidentifier 的标识列吗?如果是这样,如何?如果没有,为什么不呢?

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

我尝试在 VS2010 的服务器资源管理器中使用新表"创建它,只有当类型为 int 时,身份选项才会启用.

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.

根据 EricEJ 的建议,我确实做了专栏 PK.我也将它设置为RowGuid"

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 
      ...

我不知道 RowGuid 属性的确切用途,但它似乎具有预期的效果,即在插入时自动创建新的默认 guid 值,而无需创建它们在代码中.将默认值设为顺序 guid 会很好,但 SQL Server CE 似乎不支持.

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.

推荐答案

IDENTITY 唯一支持的类型是 int 或 bigint.但是您可以使用 Guid/uniqueidentifier 作为主键,并使用 Guid.NewGuid() 在代码中设置 this 的值.

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().

这篇关于唯一标识符作为 SQL Server CE 中的标识?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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