Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Trigger Help - code posted

Author  Topic 

abarsami
Yak Posting Veteran

68 Posts

Posted - 2001-01-18 : 15:01:31
This is a very simple question. I have one table called table1. In that table I have a Primary_key column and a Foreign_key column that refers to the Primary_key.

Pk FK
__ __
1--NULL
2--1
3--1
4--3
5--4

I say delete table1 where Pk = 4

My Trigger:

create trigger tr_table1_d
on message for delete
as
if @@rowcount = 0 return
select Pk from deleted
return

What this should do is show me the one's it deleted, but I get a foreign key constraint error, because Row 4 has a foreign key assigned to it -- row 5 refers to row 4. How can say delete row 4 and it automatically deletes row 5 first then goes and deletes row 4.

Thx
   

- Advertisement -