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 2005 Forums
 Replication (2005)
 Copy a record to a table when change

Author  Topic 

mike13
Posting Yak Master

219 Posts

Posted - 2007-08-21 : 06:57:37
Hi,

I was wondering if there is a easy way to do this.
I got Table Customers, and when a row is changed, deleted, i want to copy the original row to a backup table, so i have the whole history.

tnx a lot,

Mike

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-08-21 : 22:39:00
You can use trigger.
Go to Top of Page

mike13
Posting Yak Master

219 Posts

Posted - 2007-08-22 : 04:03:27
Okay, but how do i use a trigger (sorry never used them)

tnx,

Mike
Go to Top of Page

chadi_buddy
Starting Member

1 Post

Posted - 2007-08-22 : 04:27:13
This is an example of creating a trigger. Just attach it to the table & you'll be good to go :)

Trigger on an INSERT, UPDATE, or DELETE statement to a table or view (DML Trigger)
CREATE TRIGGER [ schema_name . ]trigger_name
ON { table | view }
[ WITH <dml_trigger_option> [ ,...n ] ]
{ FOR | AFTER | INSTEAD OF }
{ [ INSERT ] [ , ] [ UPDATE ] [ , ] [ DELETE ] }
[ WITH APPEND ]
[ NOT FOR REPLICATION ]
AS { sql_statement [ ; ] [ ,...n ] | EXTERNAL NAME <method specifier [ ; ] > }

<dml_trigger_option> ::=
[ ENCRYPTION ]
[ EXECUTE AS Clause ]
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-22 : 04:50:39
quote:
Originally posted by mike13

Okay, but how do i use a trigger (sorry never used them)

tnx,

Mike


Make use of sql server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -