自动增量PK - 使用MS还是自己增长? [英] Auto-increment PK - Use MS or Grow your own ?

查看:57
本文介绍了自动增量PK - 使用MS还是自己增长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL 2000


我以为我会把它扔到那里以获得别人的反馈。


我想知道如果您觉得使用MS自动增量字段是一个很好的

解决方案这些天还是应该自己成长?


谢谢,


我。

SQL 2000

I thought I would throw this out there for some feedback from others.

I''d like to know if you feel using MS auto-increment field is a good
solution these days or should one grow their own ?

Thanks,

Me.

推荐答案

绝对使用SQL Server自动增加主键字段。

然后没有重复的机会。

Definitely use SQL Servers to auto-increment the primary key field.
Then there is no chance of duplicates.


我可以给你一个明确的可能。


我使用了两者取决于:


*如果插入

交易被回滚,您是否关注序列中可能缺少数字?

*您是否将主键作为表的聚簇索引?

*您是否需要将该键的值填充到
$中的其他表中b $ b同样的程序?

< cs ****** @ dwr.com>在消息中写道

news:11 ********************* @ z14g2000cwz.googlegro ups.com ...
I can give you a definite Maybe.

I''ve used both depending on:

* Do you care that numbers may be missing in the sequence if insert
transactions get rolled back?
* Are you making the Primary Key the table''s clustered index?
* Do you need to populate the value of that key into other tables within
the same procedure?
<cs******@dwr.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
SQL 2000

我想我会把它扔到那里以获得别人的反馈。

我想知道你是否觉得使用MS自动增量现场是一个很好的解决方案,还是一个人应该自己成长?

谢谢,

我。
SQL 2000

I thought I would throw this out there for some feedback from others.

I''d like to know if you feel using MS auto-increment field is a good
solution these days or should one grow their own ?

Thanks,

Me.



这个问题肯定会引起一些常客关闭他们最喜欢的争论之一。仍然要加上我的价值,我会说它是'

好​​在某些情况下使用它。何时何地完全取决于您提供的解决方案以及您正在使用的数据。


我认为代理密钥是有效的,通常更多简单比

a几列主键。话虽如此,你确实得到了数字序列中带有''gap''的
实例,所以这可能不是你需要的
。您可以自行生成一个

代理密钥的路线(您的原始问题),但如果IDENTITY为您提供与您介绍更多相同的优势,我会犹豫


问题取决于您的方法。如果可能且逻辑合理,请使用

a正确定义的主键,但要用你的头并决定什么是最合适的



我完全清楚,有些常客会不同意我的意见,而且有些人会这样做。但是,我认为他们有权获得他们的b $ b。我建议为那些

不同意的人查询Occams Razor(http://pespmc1.vub.ac.be/ASC/OCCAM''_RAZOR.html)


回到你的问题,如果你'发展自己''那么这似乎是合理的,如果你做的事情是使用IDENTITY不允许

你。如果它是相同的,那么为什么要这么麻烦?


Ryan

cs ****** @ dwr.com 写道:
This question is bound to start a few of the regulars off on one of
their favorite arguements. Still to add my tuppence worth, I''d say it''s
OK to use it under some circumstances. When and where depends entirely
on the solution you are providing and the data you are working with.

Surrogate keys in my opinion are valid and often much more simple than
a primary key of several columns. Having said that, you do get
instances with ''gaps'' in the number sequence so this may not be
something you want. You could go down the route of generating a
surrogate key yourself (your original question), but I would hesitate
if IDENTITY offers you the same advantages as you may introduce more
problems depending on your approach. If possible and where logical, use
a properly defined primary key, but use your head and decide what is
most appropriate.

I know full well that some of the regulars will not agree with me and
that some will. However, it is my opinion and they are entitled to
theirs. I would suggest looking up ''Occams Razor'' for anyone who
disagrees ( http://pespmc1.vub.ac.be/ASC/OCCAM''_RAZOR.html )

Going back to your question, if you ''grow your own'' then this seems
reasonable if you are doing something that using IDENTITY doesn''t allow
you. If it''s the same, then why bother ?

Ryan

cs******@dwr.com wrote:
SQL 2000

我想我会把它扔到那里寻求一些反馈其他。

我想知道你是否觉得使用MS自动增量字段这些天是一个很好的解决方案,还是应该自己成长?
谢谢,

我。
SQL 2000

I thought I would throw this out there for some feedback from others.

I''d like to know if you feel using MS auto-increment field is a good
solution these days or should one grow their own ?

Thanks,

Me.






这篇关于自动增量PK - 使用MS还是自己增长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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