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 Development (2000)
 Delete trigger

Author  Topic 

Delinda
Constraint Violating Yak Guru

315 Posts

Posted - 2008-09-23 : 23:01:16
I've a table as follow,

CourseBooked
TransID | StudentID | CourseCode
------------------------------------
89 | 892 | A8869
90 | 892 | A3369
91 | 892 | A4469

If i've perform SQL as Delete CourseBooked where TransID=90. How to transfer this row into below table

CourseBooked_Del
TransID | StudentID | CourseCode
------------------------------------
90 | 892 | A3369

If im not mistaken, it is suppose using Delete Trigger. Hopefully anyone, can show me the accurate trigger syntax and ensure the integrity in a both table (CourseBooked - row delete, and CourseBooked_Del - row insert).

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-09-23 : 23:36:31
CREATE TRIGGER trig_CourseBooked
ON dbo.CourseBooked
AFTER DELETE
AS
Begin

Insert into CourseBooked_Del(TransID,StudentID,CourseCode)
select columns... from deleted d inner join inserted i
on d.PK = i.PK

End


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-24 : 01:51:25
quote:
Originally posted by sodeep

CREATE TRIGGER trig_CourseBooked
ON dbo.CourseBooked
AFTER DELETE
AS
Begin

Insert into CourseBooked_Del(TransID,StudentID,CourseCode)
select columns... from deleted d inner join inserted i
on d.PK = i.PK


End





No need of join with inserted. Inserted wont have any data during delete action so join will not return anything. just dump contents directly from deleted alone.
Go to Top of Page

Delinda
Constraint Violating Yak Guru

315 Posts

Posted - 2008-09-27 : 06:50:20
this info is really great.
Go to Top of Page
   

- Advertisement -