增加外键
建表的时候增加
CREATE TABLE Members (
Member_ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
First_Name VARCHAR(30) NOT NULL,
Last_Name VARCHAR(30) NOT NULL,
Birthday DATE NOT NULL,
Gender ENUM('M', 'F') DEFAULT 'F'
);
CREATE TABLE Email (
Email VARCHAR(50),
Member_ID INT NOT NULL,
PRIMARY KEY (Email, Member_ID),
CONSTRAINT FOREIGN KEY (Member_ID) REFERENCES Members(Member_ID)
ON DELETE RESTRICT ON UPDATE CASCADE
);
建表后增加外键
ALTER TABLE Email add CONSTRAINT FOREIGN KEY(Member_ID) REFERENCES Members(Member_ID)