Click here to Skip to main content
15,916,702 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have this error
"
The DELETE statement conflicted with the REFERENCE constraint "FK_Stores_Employees". The conflict occurred in database "MultiStore", table "dbo.Stores", column 'EmployeeID'.
The statement has been terminated.
"
what i have to do?
Posted

The employee record you're trying to delete is currently associated with one or more records in the Stores table.

Either update the affected records in the Stores table to associate them with a different employee; or, if the EmployeeID column allows Null values, set it to Null; or delete the associated store records.
 
Share this answer
 
Comments
Member 11321194 20-Dec-14 12:34pm    
I probably I will take it into the archive, so I will not have to delete the information.
I suspect that you have referential integrity enabled on EmployeeID to ensure that a store doesn't refer to a non-existent employee -- and then you are likely trying to delete an employee.

0) Deleting is not generally a good idea, try setting a status instead.
1) Or, remove the reference in Stores before deleting the employee.
2) This may be done by enabling cascaded deletes, but that is not a very good idea.


The reason not to delete records (such as employee records) is so you have a history of what happened in the enterprise. With a record of start and end dates you can easily query things like "when did Bob work for us and in what store?" -- if you delete the Bob record you have no way to achieve that. You will find that this is how business software works. Even if this is a student project, please do it this way to get in the habit -- it should lead to a better grade as well.
 
Share this answer
 
v2
Comments
Member 11321194 20-Dec-14 12:36pm    
How do I actually can add options (BIT) each of the employees
That way I can get the query only active employees? I have to edit all the SP you have already built?
PIEBALDconsult 20-Dec-14 15:57pm    
I wouldn't use a bit; one of the simplest techniques is to have start and end dates. When an employee leaves, set the end date. If the end date is null, you know the record is still active.
Since the data is being referenced and acts as a foreign key for another table, you need to change the value for the dependent table and then try to delete the record
 
Share this answer
 
You will trying to delete the referred record of the table. before deleting this record update the reference table value with different value or update those values as null and then delete the following row in the parent table.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900