具体的外键解释

时间:2013-01-08 22:11:26

标签: mysql sql database

基本上我对MySQL很新,在一个例子中我看到添加了这个外键:

ALTER TABLE Department ADD FOREIGN KEY managerIsInDepartment
(manager,id) REFERENCES Employee(id,worksAt);

我想添加了一个外键(名称为managerIsInDepartment)。

但我认为括号中的属性是变成外键的属性?

为什么要显示managerIsInDepartment?

1 个答案:

答案 0 :(得分:2)

managerIsInDepartment只是帮助识别密钥的密钥的名称。您可以省略它,并自动生成一个。

ALTER TABLE Department <-- Table that will have the foreign key constraint
ADD <-- Option
FOREIGN KEY managerIsInDepartment  <-- Name of the key
(manager,id) <-- Columns included in the key
REFERENCES Employee <-- The table being referenced
(id,worksAt) <-- Columns being referenced in foreign table

希望这有帮助。

reference