How to know data is update or not in sql server.

Posted by Jitendrasoft09 under Sql Server on 3/29/2013 | Points: 10 | Views : 988 | Status : [Member] [MVP] | Replies : 1
If one table having 10 fields and want to know which column or field is updated, how to find out the update field value.

Jitendra Kumar
If my post helps you, plz mark as an answer.



Responses

Posted by: lakhansin-22735 on: 7/4/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Jitendra,

There is no special statement you can run that will tell you exactly which columns has been update, but if you're trying to actually do something as a result of these changes, then best to write a trigger:

CREATE TRIGGER trToCatchUpdate

ON tbl
FOR UPDATE AS
BEGIN
IF UPDATE(c1) OR UPDATE(c2)
INSERT tblChanges (Oldc1, Newc1, Oldc2, Newc2)
SELECT d.c1, i.c1, d.c2, i.c2
FROM inserted i
INNER JOIN deleted d
ON i.id = d.id
WHERE d.c1<> i.c1
OR d.c2 <> i.c2
END

Of course you want to do more than in this trigger, but this is an example to demonstrate a simple way by which you can achieve what you really want.

Hope somehow this will help you.

Thanks,

Lakhan Singh
Tech Lead
BeyondKey System Pvt. Ltd.
Indore, M.P.
India

Jitendrasoft09, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response