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
 General SQL Server Forums
 New to SQL Server Programming
 SQL Triggers

Author  Topic 

xrum
Yak Posting Veteran

87 Posts

Posted - 2011-02-22 : 09:30:58
i've been looking though different tutorials online,but i can't seem to find what i need.

I need to copy a record into a history table, every time it is updated.

Is there a way to do it with triggers without having to type out all of my data fields?

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-02-22 : 12:34:43
if you are using SLQ 2008, have a look at Change Data Capture ... hope that helps
Go to Top of Page

xrum
Yak Posting Veteran

87 Posts

Posted - 2011-02-22 : 14:35:31
i did the following:


TRIGGER [dbo].[trg_SourceHistory]
ON [dbo].[tblSource]
for UPDATE
AS

INSERT INTO tblHistorySource

select *, getdate()

from INSERTED

BEGIN
RAISERROR('Error in Source Hisotry Trigger' ,16,1)
ROLLBACK TRAN
END


but i'm getting an error in the trigger when trying to execute an update on that table, so no changes are saved. please ehlp
Go to Top of Page

xrum
Yak Posting Veteran

87 Posts

Posted - 2011-02-22 : 15:12:41
nevermind :) i got it
Go to Top of Page
   

- Advertisement -