定义外键约束:FOREIGN KEY
CREATE TABLE stu(
sid int pirmary key,
name varchar(50) not null,
);
CREATE TABLE score1(
score int,
sid int , --外键列的数据类型一定要与主键的类型一致
CONSTRAINT fk_score1_sid foreign key (sid) references stu(id)
);
定义外键约束:FOREIGN KEY
CREATE TABLE stu(
sid int pirmary key,
name varchar(50) not null,
);
CREATE TABLE score1(
score int,
sid int , --外键列的数据类型一定要与主键的类型一致
CONSTRAINT fk_score1_sid foreign key (sid) references stu(id)
);