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
 Transact-SQL (2000)
 Delete Trigger

Author  Topic 

ilimax
Posting Yak Master

164 Posts

Posted - 2008-04-29 : 10:31:19
I created this trigger on the table and works fine if I delete sigle record in Table1. If I delete more then one record from my application written in VB6 (by running delete query and ADO command object), trigge delete only one record in Table2.

Does anybody have ideay why? How can make trigger so trigger delete all same records in Table2 when I delete more then one records in Table1?

Here is my trigger ....

CREATE TRIGGER deleteTable1 ON [dbo].[Table1]
FOR DELETE
AS
DECLARE @TID int;

SELECT @TID=d.[ID] FROM deleted d;
BEGIN
DELETE FROM [Table2] WHERE [POID]=@TID
END

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-29 : 10:35:32
[code]CREATE TRIGGER DeleteTable1 ON dbo.Table1
FOR DELETE
AS

SET NOCOUNT ON

DELETE T2
FROM Table2 AS t2
INNER JOIN deleted AS d ON d.ID = t2.PoID[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

ilimax
Posting Yak Master

164 Posts

Posted - 2008-04-29 : 10:50:30
It works! Thank you very much.

Tell me, do I need to use BEGIN and END between query in triggers?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-29 : 11:06:41
Don't think so.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

ilimax
Posting Yak Master

164 Posts

Posted - 2008-04-29 : 11:25:29
Thank you very much.
Go to Top of Page
   

- Advertisement -