English 中文(简体)
是否有一个表(联系表)主要关键? 许多关系
原标题:Does a Join table (association table) have a primary key ? many to many relationship

是否有一个表(联系表)主要关键? 许多与许多关系。 我看到了约恩的一些表格,其中主要有关键,有些人没有这样的表格,请解释一下,什么时候你会把主要钥匙放在合并桌上?

事先感谢你;

最佳回答

在纯粹的合并或交叉口表中,所有领域都将是主要领域的一部分。 例如,请考虑以下表格:

CREATE TABLE USERS
  (ID_USER NUMBER PRIMARY KEY,
   FIRST_NAME VARCHAR2(32),
   LAST_NAME VARCHAR2(32));

CREATE TABLE ATTRIBUTES
  (ID_ATTRIBUTE NUMBER PRIMARY KEY,
   ATTRIBUTE_NAME  VARCHAR2(64));

允许许多用户具有许多属性之间的交叉口表将是

CREATE TABLE USER_ATTRIBUTES
  (ID_USER NUMBER REFERENCES USERS(ID_USER),
   ID_ATTRIBUTE NUMBER REFERENCES ATTRIBUTES(ID_ATTRIBUTE),
   PRIMARY KEY(ID_USER, ID_ATTRIBUTE));

有时,你认为有必要在禁止令表中增加一个非主要栏目,但我认为这相对较少。

分享和享有。

问题回答

所有表格都应具有首要关键意义。

你们要么使用混杂的外国钥匙,要么使用盲人注射器。

如果在您的协会桌上没有其他要素,你将使用该化合物的外国钥匙。

在协会桌上有自己的要素时,你可以使用盲人注射器。 将用另外两个指数确定化合物外壳。

这取决于你所参与的记录。 只要你不需要每个协会的多份记录,你就可以在相关记录的id上形成一个综合的主要关键。

然而,更重要的是,确保这两个栏目都有索引,并界定了参考性完整性。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...