复合键有什么用? [英] what is the use of composite key?

查看:58
本文介绍了复合键有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有三张桌子,



1.主表



2.交易表



3. master_transaction_link表



这里我的问题是,在链接表中,有id, mstrid,transid - mstrid是mster表的id,transid是trans表的id



为什么我要将mstrid和transid设置为链接表中的复合键。?< br $> b $ b



链接表中复合键的用途是什么?

hi all, i have three tables,

1. master table

2. transaction table

3. master_transaction_link table

here my question is, in link table, which has id,mstrid,transid - mstrid is id of mster table and transid is id of transction table

why should i set the mstrid and transid as composite key in link table.?


what is the use of composite key in link table?

推荐答案

这个参考文献可能会给你答案。

请参考这里,

http://www.techopedia.com/definition/6572/composite-key [ ^ ]
This reference would probably give you the answer for your question.
Please refer here,
http://www.techopedia.com/definition/6572/composite-key[^]


请参阅: http://www.techopedia.com/definition/6572/composite-key [ ^ ]。它声明:

See this : http://www.techopedia.com/definition/6572/composite-key[^]. It states that :
Quote:

复合键,在关系数据库的上下文中,是两个的组合表中的多个或多个列,可用于唯一标识表中的每一行。 只有在组合列时才能保证唯一性,当单独使用时,列不保证唯一性。

A composite key, in the context of relational databases, is a combination of two or more columns in a table that can be used to uniquely identify each row in the table. Uniqueness is only guaranteed when the columns are combined, when taken individually the columns do not guarantee uniqueness.


复合键的使用是: -

如果你在两列上定义主键,那么列就不能重复记录。

复合键将这两列都当作主键。



例如。你有链接表,该表有mstrid和transid列。你分配了

主键(mstrid,transid),然后他们两列都可以接受唯一值。



mstrid transid

1 1001

2 1002


允许,但是你要在同一个mstrid和transid的链接表中再次插入相同的记录然后它不允许。



mstrid transid

1 1001






欲了解更多详情,请阅读以下链接: -

http://weblogs.sqlteam.com/jeffs/archive/2007/08/23/composite_primary_keys.aspx [ ^ ]

http://www.techopedia.com/definition/6572/composite-key [ ^ ]
use of composite key is that:-
If you define primary key on two columns then columns can not take duplicate records.
composite key treat both of those columns as primary key.

eg. you have link table and that table has mstrid and transid columns. you have assign
primary key(mstrid ,transid) then they both columns can accept unique values.

mstrid transid
1 1001
2 1002

it allowed but you going to insert same record again in link table with same mstrid and transid then it is not allowed.

mstrid transid
1 1001



For more details read below links:-
http://weblogs.sqlteam.com/jeffs/archive/2007/08/23/composite_primary_keys.aspx[^]
http://www.techopedia.com/definition/6572/composite-key[^]


这篇关于复合键有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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