Take the common example of Employee - Manager relationship:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaykA6yURBrucne_VJEpwktw2ShSifCwbmiiFp50ohMVdJODSQ2QJZvh17TN8fAa8HC_g9CTj1q_wVpx46hKE_iZi7jPRpofuF71Nh2tVoBc-pas0Y_Mm0promO5ME81hxrREEpKuWw5E/s400/Employee_table_self_reference.png)
No rows were deleted.
A problem occurred attempting to delete row 1.
Error Source: .Net SqlClient Data Provider.
Error Message: The DELETE statement conflicted with the SAME TABLE REFERENCE constraint "FK_Employee_Employee". The conflict occurred in database "test", table "dbo.Employee", column 'ManagerId'.
The statement has been terminated.
Using the Query window and running:
DELETE employee
Will work however.
The difference is that SSMS actually tries to delete row by row, which will violate the constraint. But when using a query to delete all records. SQL Serve is smart enough to clear all data.
No comments:
Post a Comment