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
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now