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 2005 Forums
 Transact-SQL (2005)
 SQL Insert Trigger (DEL from A on INS into B)

Author  Topic 

jportnoy
Starting Member

7 Posts

Posted - 2007-05-29 : 11:32:41
SQL newbie question =(

Table A:
field1

Table B:
field1
field2

I'm trying to create a SQL trigger that deletes all records in B where (B.field1 = A.field1) when a record is inserted into Table A.

I have this:

CREATE TRIGGER tgMyTrigger
ON TableA
FOR INSERT
AS
BEGIN
DELETE
FROM TableB
WHERE (TableB.field1 = Inserted.field1)
END
GO

I keep getting "The multi-part identifier "Inserted.field1" could not be bound."

I had this trigger working on Friday, but I was trying to rush out of the office and accidently deleted it.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-29 : 11:35:19
[code]Delete B
From TableB B Join Inserted I
on B.Field1 = I.Field1[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

arvind
Starting Member

12 Posts

Posted - 2007-05-30 : 17:53:45
hi
try this
CREATE TRIGGER tgMyTrigger
ON TableA
FOR INSERT
AS
BEGIN
DELETE
FROM TableB
WHERE (TableB.field1 = (Select field1 from Inserted))
END
GO
Go to Top of Page

aravindt77
Posting Yak Master

120 Posts

Posted - 2007-06-01 : 06:17:28
HI TRY OUT FOR THIS,,,,

CREATE TRIGGER TEST_TRIGGER
ON A
FOR INSERT
AS0
BEGIN
DELETE FROM B
WHERE COL2 IN (SELECT DISTINCT COL2 FROM INSERTED)
PRINT ' OK'

END


PLZ GO THRU IT ...FOUND SUCCESS IN MY TEST CASE
Go to Top of Page
   

- Advertisement -