SQL主键,INT还是GUID或..? [英] SQL primary key, INT or GUID or..?

查看:696
本文介绍了SQL主键,INT还是GUID或..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么原因我不应该使用整数作为我的表的主键?

Is there any reason why I should not use an Integer as primary key for my tables?

数据库是SQL-CE,每年约有50,000个条目的两个主表和一些次表。只有两个连接将不断地存在于数据库中。但更新将通过多个TCP套接字连接触发,因此将有许多交叉线程访问和使用相同的数据库连接。虽然活动非常低,因此同时更新是不太可能,但可能会发生,可能是每天最多两次。

Database is SQL-CE, two main tables of approx 50,000 entries per year, and a few minor tables. Only two connections will exist constantly open to the database. But updates will be triggered through multiple TCP socket connections, so it will be many cross threads that access and use the same database-connection. Although activity is very low, so simultanous updates are quite unlikely, but may occur maybe a couple of times per day max.

可能会将LINQ2SQL用于DAL或类型化的数据集。

Will probably use LINQ2SQL for DAL, or typed datasets.

不确定这些信息是否相关,但这是为什么我问,因为我不知道:)

Not sure if this info is relevant, but that's why I'm asking, since I don't know :)

推荐答案

使用 GUID primkey的优点是它在世界上应该是唯一的,例如是否移动数据一个数据库到另一个。所以你知道该行是唯一的。

The advantage of using GUID primkey is that it should be unique in the world, such as whether to move data from one database to another. So you know that the row is unique.

但是如果我们谈论一个小数据库,所以我喜欢整数。

But if we are talking about a small db, so I prefer integer.

编辑

如果您使用SQL Server 2005 ++,还可以使用 NEWSEQUENTIALID()
这将根据上面的行生成一个GUID。允许索引问题与newid ()不再存在了。

If you using SQL Server 2005++, can you also use NEWSEQUENTIALID(), this generates a GUID based on the row above.Allows the index problem with newid() is not there anymore.

这篇关于SQL主键,INT还是GUID或..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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