基本上我对MySQL很新,在一个例子中我看到添加了这个外键:
ALTER TABLE Department ADD FOREIGN KEY managerIsInDepartment
(manager,id) REFERENCES Employee(id,worksAt);
我想添加了一个外键(名称为managerIsInDepartment)。
但我认为括号中的属性是变成外键的属性?
为什么要显示managerIsInDepartment?
答案 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
希望这有帮助。