创建表时添加外键约束
create table student4(
cnou char(10) primary key,
stuno CHAR(11) ,
stuname VARCHAR(12),
cno varchar(8) ,
stusex CHAR(1) ,
schno CHAR(3) ,
FOREIGN KEY (stuno) REFERENCES student3(stuno)
)
创建表时添加外键约束并为外键命名
create table student4(
cnou char(10) primary key,
stuno CHAR(11) ,
stuname VARCHAR(12),
cno varchar(8) ,
stusex CHAR(1) ,
schno CHAR(3) ,
CONSTRAINT stuno FOREIGN KEY (stuno) REFERENCES student3(stuno)
)
创建表后再添加外键约束
ALTER TABLE student4
ADD
FOREIGN KEY (stuno)
REFERENCES student3(stuno)
创建表后再添加外键约束并为外键命名
ALTER TABLE student4
ADD CONSTRAINT stuno
FOREIGN KEY (stuno)
REFERENCES student3(stuno)