INSERT statement conflicted with the FOREIGN KEY constraint - SQL Server

前端 未结 14 1305
-上瘾入骨i
-上瘾入骨i 2020-11-22 11:09

I am getting the following error. Could you please help me?

Msg 547, Level 16, State 0, Line 1
The INSERT statement conflicted with the FOREIGN

14条回答
  •  旧巷少年郎
    2020-11-22 11:48

    I ran into this problem when my insert value fields contained tabs and spaces that were not obvious to the naked eye. I had created my value list in Excel, copied, and pasted it to SQL, and run queries to find non-matches on my FK fields.

    The match queries did not detect there were tabs and spaces in my FK field, but the INSERT did recognize them and it continued to generate the error.

    I tested again by copying the content of the FK field in one record and pasting it into the insert query. When that record also failed, I looked closer at the data and finally detected the tabs/spaces.

    Once I cleaned removed tabs/spaces, my issue was resolved. Hope this helps someone!

提交回复
热议问题