自动编号与密钥 [英] AutoNumber vs. Key

查看:69
本文介绍了自动编号与密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我总是对使用什么作为桌子的钥匙感到困惑。


让我们说我有公司 - 员工的桌子。


[公司] --- * [员工]


我的同事喜欢使用自动编号或计数器作为

[员工]表(以及所有内容)的关键。

我个人使用[员工]表的实际密钥集。


因此,他的表将有一个(Autonumber或LONG)列作为键。

company_id只是另一个属性。

另一方面,Mine有两列作为关键字。 (即)company_id +

employee_id


那么,这笔交易是什么?


-

Hi,

I am always confused about what to use as the key for a table.

Let''s say I have a company-employee table.

[company]---*[employee]

My co-worker likes to use an AutoNumber or Counter as the key for the
[employee] table (and everything).
I personally use an actual key set for the [employee] table.

So, his table will have one (Autonumber or LONG) column as the key. The
company_id is just another attribute.
Mine, on the other hand, has 2 columns as the key. (i.e.) company_id +
employee_id

So, what is the deal?

--

没有答案。
没有答案。
没有答案。
这就是答案!
我被搞砸了。
截止日期是昨天到期的。

生命没有意义。
这就是重点。
我们被搞砸了。
我们将用完很快。
There is no answer.
There has not been an answer.
There will not be an answer.
That IS the answer!
And I am screwed.
Deadline was due yesterday.

There is no point to life.
THAT IS THE POINT.
And we are screwed.
We will run out of oil soon.


推荐答案

总是使用自动编号识别你做的每一件事


单列主键

always use an autonumber identity for everythign you do

single-column primary key


" For everything"是一个相当模糊的答案。其他钥匙很重要

。在一个仅包含两个外键的连接表中,例如

IDENTITY的用途是什么?


汤姆,对于辩论你可以谷歌为自然键 ;和代理

Key在这个组和microsoft.public.sqlserver.programming中。


-

David Portas

SQL Server MVP

-

"For everything" is a pretty obscure answer. Other keys are important
too. In a joining table containing only two foreign keys for example
what purpose would IDENTITY serve?

Tom, for the debate you can Google for "Natural Key" and "Surrogate
Key" in this group and in microsoft.public.sqlserver.programming.

--
David Portas
SQL Server MVP
--





有没有理由只使用一个一列是关键?

我觉得用这种设计很难强化数据库的完整性。


例如,

让我们说[公司] - [员工] - [销售]表格。

公司A有一名员工B.

员工B进行销售C 。


如果员工B搬到另一家公司,[销售]表中的销售额C将与员工B一起搬到新公司。

这对我来说看起来不对。


< db ******* @ hotmail.com>在消息中写道

news:11 ********************* @ g47g2000cwa.googlegro ups.com ...
Hi,

Is there a reason for using one and only one column as the key?
I find it hard to enforce the integrity of the database with this design.

for example,
let''s say the [company]-[employee]-[sale] tables.
company A has an employee B.
employee B makes a sale C.

If employee B moves to another company, the sale C in the [sale] table will
move along with employee B to the new company.
This doesn''t look correct to me.

<db*******@hotmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
总是使用自动编号为你做的每一个

单列主键
always use an autonumber identity for everythign you do

single-column primary key



这篇关于自动编号与密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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