mysql引用完整性

mysql引用完整性[数据库教程]

###引用完整性
学生表
 id
 名字
 性别

成绩表
 id
 学生ID
 成绩

create table stu7(
 id int primary key,
 name varchar(50)
)
create table score(
 id int primary key,
 sid int,
 score double,
 constraint aa foreign key (sid)  references stu7(id)
)

insert into stu7(id,name) values(1,"zsf");
insert into score(id,sid,score) values(1,1,90);

ERROR 1452 (23000): Cannot add or update a child
row: a foreign key constraint fails (`db_0402`.`score`,
 CONSTRAINT `aa` FOREIGN KEY (`sid`) REFERENCES `stu7` (`id`))

mysql引用完整性

原文:https://www.cnblogs.com/sxwa/p/14651550.html