添加外键约束
CREATE TABLE stu( sid INT PRIMARY KEY, NAME VARCHAR(50) NOT NULL );
添加外键约束方式一
CREATE TABLE score1( score DOUBLE, sid INT, CONSTRAINT fk_stu_score1_sid FOREIGN KEY(sid) REFERENCES stu(sid) );
添加外键约束方式二(若表已存在,可用这种)
CREATE TABLE score1( score DOUBLE, sid INT ); ALTER TABLE score1 ADD CONSTRAINT fk_sid FOREIGN KEY(sid) REFERENCES stu(sid)