引用完整性

 

     主外键的关系,2个表之间建立管理关系之和,他们删除,更新操作都是受影响的。

##引用完整性

学生表

   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-13 09:05  啊阿啊  阅读(98)  评论(0)    收藏  举报