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 2008 Forums
 Transact-SQL (2008)
 Detect Column and Table changes

Author  Topic 

amitranjan
Starting Member

45 Posts

Posted - 2011-01-05 : 06:27:06
I need a sp or trigger to detect if any of the field in table is updated/inserted/deleted then the query or trigger will be able to detect - on what table has and what columns. For example I have table tblAddress having column Address, WorkPhone, CellPhone, City, State etc. If a user only updates WorkPhone then the query should be able to detect that in table address phone number has been updated and the message will be inserted to another table called tblHistory.

I hope my question is clear....

amit Ranjan

Kristen
Test

22859 Posts

Posted - 2011-01-05 : 07:31:13
You need a Trigger to do that. Every time a row is Inserted, Deleted or Updated the "before" can be stored in a History table. We do that for MOST of the tables in our application, and it is extremely useful for working out what-happened-and-when.

See: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=170215
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-14 : 08:38:11
in 2008 you also have feature called change data capture which can used for above scenarios

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -