Taggs Posted August 1, 2006 Posted August 1, 2006 Please excuse my basic knowledge of SQL.I have two tables on a MS SQL2000 sp4 databaseTable name - DetailsidforenameSurnamedobemailTable name - DetailsHistoryidforenameSurnamedobemailWhen somebody changes (Update) a row in Details, I want to create a trigger to : Before the change is made copy the current row to the DetailsHistory tablehere is my codeCREATE TRIGGER savetohistory on [dbo].[Details] for updateas BEGIN INSERT into DetailsHistory select * from Details where id = Details.idEND;but this copies ALL the rows not just the current row Taggs
uid0 Posted August 1, 2006 Posted August 1, 2006 You want to select from the DELETED table, to copy out the row(s) to be updated.This will ignore deletes and inserts, only fire for updates.CREATE TRIGGER savetohistory on [dbo].[Details] for updateas BEGIN INSERT into DetailsHistory select * from DELETEDEND;
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now