Error re SQL server statement Foreign key conflict

Kayleigh

Member
Local time
Today, 08:58
Joined
Sep 24, 2020
Messages
709
Hi there,

I am managing a MS Access DB coupled with SQL Server backend.

Occasionally users report that records go missing and I it may have to do with the following error although I am not clear on what it means and what to do about it. If anyone can enlighten me I would appreciate!

WhatsApp Image 2024-03-04 at 14.59.18.jpeg
 

Attachments

  • WhatsApp Image 2024-03-04 at 14.59.18.jpeg
    WhatsApp Image 2024-03-04 at 14.59.18.jpeg
    360.7 KB · Views: 219
Last edited:
The insert statement conflicted with the foreign key constraint X.
A foreign key (FK) is usually a number that refers to a record in a related table. Simple example: the Northwind sample database Orders table has a CustomerID field. That is a FK that refers to a Customer record in the Customers table. If you try inserting an Order with a non-existing CustomerID, KABOOM, and for good reasons. After all, if you cannot look up the customer in the Customers table, then where are you going to send the products, and the invoice?
You need to tease apart the name of the FK, and it will tell you which relation in the database you are violating.
BTW, inserting that Customer record (to keep the example going) a millisecond later is not good enough. Insert the parent record (Customer) first, then insert the child record (Order).
 
Thanks for your suggestions @Pat Hartman

The tables are in SQL Server so how would I check it is Null not 0 in SSMS ?

Note - these are tables we have been using for many years without an issue!
 

Users who are viewing this thread

Back
Top Bottom