Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trigger After Delete Problem

1 view
Skip to first unread message

Edgar_Torres

unread,
Jul 10, 2007, 11:58:55 AM7/10/07
to
Hi, I create a trigger that write a few fields form table A to tableB,
works fine, but if I delete one record in table A I want delete in
tableB too, I wrote this trigger but don't work.

Thanks, i Apreciate your help

Edgar

ALTER TRIGGER [TGRDELETE]
ON [dbo].[test01]
AFTER DELETE
AS
BEGIN
delete test02 from test02
inner join deleted on
test02.norec = deleted.norec
where test02.norec = deleted.norec
END

Aaron Bertrand [SQL Server MVP]

unread,
Jul 10, 2007, 12:24:58 PM7/10/07
to
What is the problem? Do you get an error message? If so, what is it?


"Edgar_Torres" <torres...@gmail.com> wrote in message
news:1184083135....@n2g2000hse.googlegroups.com...

Anith Sen

unread,
Jul 10, 2007, 2:23:39 PM7/10/07
to
Not sure what you meant by "don't work", but try:

DELETE FROM Destination t
WHERE EXISTS ( SELECT *
FROM deleted d
WHERE d.key = t.key )

-- where key is the unique column or set of columns that can identify a row
in the table.

A better alternative to trigger is to use the cascading features of the
referential integrity constraint. You should be able to find out more about
it from SQL Server Books Online.

--
Anith


0 new messages