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
 Old Forums
 CLOSED - General SQL Server
 Update Trigger

Author  Topic 

sr_aneesh
Starting Member

17 Posts

Posted - 2005-01-31 : 06:41:53
i made a trigger to track the changes made to a record in a table.
I want that whenever any record is updated (only when a record is updated) a new record should be added in to the table1

I wrote the following Trigger but when ever i Click the Update Button even if i dont make any changes to the Record a new record is inserted in to the table1.




CREATE TRIGGER Contrack_update ON maintable AFTER UPDATE
AS
IF @@ROWCOUNT=0 RETURN
INSERT table1
SELECT * FROM inserted





I want that a new record should be insertted only if any changes is made to any record

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-01-31 : 07:44:12
you could use COLUMNS_UPDATED()
look that up in BOL under Create Trigger example E.

Go with the flow & have fun! Else fight the flow
Go to Top of Page

sr_aneesh
Starting Member

17 Posts

Posted - 2005-01-31 : 07:53:39
what is BOL?
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-01-31 : 07:57:31
It's Books Online. It comes free with SQL Server. It should be your best friend if you are going to use SQL Server and actually understand the tool you're using.

Start/All Programs/Microsoft SQL Server/Books Online.

Sleep with it for a few days. Read it from front to back. You will be a better person for it.

MeanOldDBA
derrickleggett@hotmail.com

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

- Advertisement -