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.
Author |
Topic |
Delinda
Constraint Violating Yak Guru
315 Posts |
Posted - 2008-09-23 : 23:01:16
|
I've a table as follow,CourseBookedTransID | StudentID | CourseCode------------------------------------89 | 892 | A886990 | 892 | A336991 | 892 | A4469If i've perform SQL as Delete CourseBooked where TransID=90. How to transfer this row into below tableCourseBooked_DelTransID | StudentID | CourseCode------------------------------------90 | 892 | A3369If 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_CourseBookedON dbo.CourseBookedAFTER DELETEASBeginInsert into CourseBooked_Del(TransID,StudentID,CourseCode)select columns... from deleted d inner join inserted ion d.PK = i.PKEnd |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-24 : 01:51:25
|
quote: Originally posted by sodeep CREATE TRIGGER trig_CourseBookedON dbo.CourseBookedAFTER DELETEASBeginInsert into CourseBooked_Del(TransID,StudentID,CourseCode)select columns... from deleted d inner join inserted ion d.PK = i.PKEnd
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. |
|
|
Delinda
Constraint Violating Yak Guru
315 Posts |
Posted - 2008-09-27 : 06:50:20
|
this info is really great. |
|
|
|
|
|