Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
2.2k views
in SQL Queries by 21 20 26
edited by

In SQL Server Management Studio, I have created two tables like

  1. Employee,
  2. Department,

I have set the relation between department and employee as a one-many relation. but when I delete a row from the Employee table, I got this error

The DELETE statement conflicted with the REFERENCE constraint

I am a beginner, started learning the database concepts, and I need help to fix this error?


1 Answer

1 like 0 dislike
by 24 26 40
selected by
 
Best answer

The error occurs because Enforce foreign key Constrain=Yes and Also Delete rule =No Action You can change the value of Enforce foreign key Constrain=No Or Change Delete Rule

DELETE statement conflicted with the REFERENCE constraint

In Delete Rule, there Are four choices

  1. No Action: in this case, you will get the Error message.
  2. Cascade: if you chose this when you delete record from the Department tables will also Delete Employee in this Department.
  3. Set Null: set value to NULL.
  4. Set Default: If you added Default constraint in the Employee table when you choose this choice it will add the default values.

You can see also Modify Foreign Key Relationships

If you don’t ask, the answer is always NO!
...