Best way to implement the last modified column in Sql Server 2005?

How do you implement the last modified column in SQL?

I know that for a column created by date, you can simply set the default value getdate(). For the latest changes, I always used triggers, but it seems like there should be a better way.

Thanks.

+3
source share
5 answers

Triggers are the best way because this logic is closely related to the table, not to the application. This is almost the only obvious correct use of the trigger that I can think of, in addition to more detailed referential integrity.

, "-" . " " , , ? .

+5

- // , , .

, .

, , , . , , , - , .

+3

DEFAULT, . , .

, ""

UPDATE
   table
SET
   blah,
   LastUpdatedDateTime = DEFAULT
WHERE
   foo = bar
+2

- . ​​ , . , - , , .

, , , .

+1

, , last_updated_by , . , , , .

A trigger is the only method you can use to do this. And to those who said that triggers are evil, no, they are not. They are the best way — to date — to maintain data integrity, which is more complex than a simple standard or restriction. They really should be written by people who really know what they are doing, though. But then this applies to most things that affect the design and integrity of the database.

+1
source

All Articles