troubleshooting Question

FK delete question

Avatar of wasabi3689
wasabi3689Flag for United States of America asked on
Microsoft SQL ServerMicrosoft SQL Server 2008SQL
9 Comments1 Solution761 ViewsLast Modified:
I have 3 tables. WORK, SYSTEM and TASKS

The relationship among these 3 tables are

WORK has PK WORK_ID
SYSTEM has WORK_ID but it is FK as name "ST_WRK_FK"
TASKS has WORK_ID but it is FK as name "ET_WRK_FK"

Now I want to remove records in WORK. First I delete all its child tables records associated with it

step 1
delete
from SYSTEM
Where....

step 2
delete
from TASKS
where....

step 3
delete
from WORK
where

Now I turn out the following error


Msg 547, Level 16, State 0, Line 4
The DELETE statement conflicted with the REFERENCE constraint "ET_WRK_FK". The conflict occurred in database "test1", table "dbo.TASKS", column 'WORK_ID'.
The statement has been terminated.


I check the tables TASKS and SYSTEM, all the associated records are removed. I don't understand why I cannot remove records from WORK which is the parent table.

What I went wrong? How to fix this issue?
ASKER CERTIFIED SOLUTION
Ioannis Paraskevopoulos

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros