引用完整性

##引用完整性

学生表

   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 as 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 aaFOREIGN KEY (sid)REFERENCESstu7(id))

 

posted @ 2021-04-19 09:00  啊阿啊  阅读(59)  评论(0)    收藏  举报