I found a problem when I was studying the database today. The prompt is as follows: The alter table statement conflicts with the foreign key constraint "fk_student_parents_id_parents_id. This conflict occurs in the Database "school", table "DBO. Parents", column 'id '. I still need to paste my two tables into a graph: This is the parents table: This is the student table:
The statement for creating a foreign key is as follows: Use school <br/> go <br/> alter table student <br/> Add constraint fk_student_parents_id_parents_id <br/> foreign key (parents_id) <br/> references parents (ID) <br/> go The problem lies in the selected two rows, because the parents_id of 2006006 is 2005, and this ID does not exist in the table parents. Similarly, the parents with ID 2007 does not appear in the student table. That is to say, the two tables do not match when there is excess data. Just delete the two rows. PS: the data generated by several experiment statements provided in the tutorial I learned when I got the data in these two rows. |