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
 General SQL Server Forums
 New to SQL Server Programming
 Adding a Date Modified Column

Author  Topic 

InNomina
Starting Member

40 Posts

Posted - 2012-01-04 : 12:48:43
Synopsis...

I would like 2 columns in my record.
Date Created< which is easy and I have this already>
Date Modified< Which is my issue>

I have users that access table information through a 3rd party product. When the table information is changed in any way I would a column called DATE MODIFIED to automatically change the date in that column to reflect the date any data in that particular record was changed.

Your thoughts are greatly appreciated!

Neil

-------------------------
"If you never fail, you're not trying hard enough"

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-04 : 12:53:05
you need to have a UPDATE trigger created in table for that. it will be like below


CREATE TRIGGER GetModifiedDate
ON table
AFTER UPDATE
AS
BEGIN
UPDATE t
SET t.[Date Modified]= GETDATE()
FROM table t
INNER JOIN INSERTED i
ON i.PK = t.PK
END



PK will be primary key of your table
Also make sure nested triggers setting is set to false in server

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

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-04 : 13:27:16
How about a date mollified column?





Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -