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 2000 Forums
 SQL Server Development (2000)
 Creating a Log

Author  Topic 

CLages
Posting Yak Master

116 Posts

Posted - 2004-08-11 : 20:30:49
I have a table with (in this sample) 3 columns

Maintable

Code Name Date
123 ppppp yyyy
124 rrrrr wwww


Logtable

User Seq Code Name Date
Mary 1 123 xxxx yyyy
mary 2 124 zzzz wwww


each time that mainTable is Updated, I want to get all Columns Before Changes and Insert in a LogTable adding the UserName and seq.

in this case Name of code 123 was changed to ppppp then in Logtable
i have the OldName and who did the changes.

how to do this in a table with many columns?

Tks

Carlos Lages
Netcobol + SQL + Cristal
www.adtoos.com

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2004-08-11 : 20:45:48
Have a read up on triggers in Books Online. They will do exactly what you need.
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-08-12 : 11:04:13
You'll want an UPDATE trigger. You will take the results from the deleted table and put them into your new table with the UserName and seq number. Like timmy said, Books Online gives you a great example of this. You should be able to just cut/paste/modify.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -