不为主键使用自动递增数字的原因 [英] Reasons not to use an auto-incrementing number for a primary key

查看:42
本文介绍了不为主键使用自动递增数字的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在处理其他人的数据库,其中主键是通过查找表生成的,该表包含表名列表和最后使用的主键.存储过程会增加此值并检查它是否唯一,然后再将其返回给调用插入"的 SP.

I'm currently working on someone else's database where the primary keys are generated via a lookup table which contains a list of table names and the last primary key used. A stored procedure increments this value and checks it is unique before returning it to the calling 'insert' SP.

使用这样的方法(或仅生成 GUID)而不是仅使用身份/自动编号有什么好处?

What are the benefits for using a method like this (or just generating a GUID) instead of just using the Identity/Auto-number?

我不是在谈论实际上意味着"诸如 ISBN 或产品代码之类的主键,而是唯一标识符.

I'm not talking about primary keys that actually 'mean' something like ISBNs or product codes, just the unique identifiers.

谢谢.

推荐答案

在您使用复制的情况下,自动生成的 ID 可能会导致问题(因为我确信您发现的技术可以!).在这些情况下,我通常会选择 GUID.

An auto generated ID can cause problems in situations where you are using replication (as I'm sure the techniques you've found can!). In these cases, I generally opt for a GUID.

如果您不太可能使用复制,那么自动递增的 PK 很可能会正常工作.

If you are not likely to use replication, then an auto-incrementing PK will most likely work just fine.

这篇关于不为主键使用自动递增数字的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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