fikir
Programmer
- Jun 25, 2007
- 86
I have two tables they have a foreign key relationship
tbl1
col1 col2 col3
1 1 a
2 1 b
3 2 c
tbl2
col1 col2
1 aa
2 bb
the foreign key is defined on col2 of tbl1 referncing col1 of tbl2
I am tring to delete data from both tables and wrote this kind of query
delete from tbl1
from tbl1 inner join tbl2
on tbl1.col2 = tbl2.col1
where tbl2.col1 = 1
delete from tbl2
where col1 = 1
it delete the records from tbl1 but when it is trying to delete records from tbl2, it is failing because of foreign key conflict
here is the error
DELETE statement conflicted with COLUMN REFERENCE constraint fk_col2 in database x table tbl1 column col2
and it is not deleting data from tbl1, I couldn't figuring it out why it is failing,
somebody has an idea why is is failing?
Thanks,