"Conflict between the alter table statement and the foreign key constraint"

Source: Internet
Author: User

 

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.