How to check a column in a table ,value, update

Posted by Raja_89 under C# on 9/18/2013 | Points: 10 | Views : 642 | Status : [Member] | Replies : 3
Hai

I am a updating a column in a table using update statement
Is it possible to check that column has updated with new value with a keyword in sql server




Responses

Posted by: Bandi on: 9/18/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Yes we should write triggers to know the column has been updated....
Can you explain your scenario clearly... we will provide you the solution/workaround

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Posted by: Bandi on: 9/18/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Sample of UPDATE Trigger to know the lastname in Employees table has been updated
CREATE TRIGGER tr_Employees_U on Employees FOR UPDATE AS

IF UPDATE(lastname)
BEGIN
SELECT 'LastName is updated'
RETURN
END
GO


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Posted by: Bandi on: 9/18/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
CREATE TRIGGER tr_Employees_U on Employees FOR UPDATE AS

IF ( DELETED.LastName != INSERTED.LastName) -- Checking for new value update
BEGIN
SELECT "LastName is updated with new value'
END
GO


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Login to post response