I need to create a new DATETIME
column in SQL Server that will always contain the date of when the record was created, and then it needs to automatically update whenever the record is modified. I've heard people say I need a trigger, which is fine, but I don't know how to write it. Could somebody help with the syntax for a trigger to accomplish this?
In MySQL terms, it should do exactly the same as this MySQL statement:
ADD `modstamp` timestamp NULL
DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
Here are a few requirements:
- I can't alter my
UPDATE
statements to set the field when the row is modified, because I don't control the application logic that writes to the records. - Ideally, I would not need to know the names of any other columns in the table (such as the primary key)
- It should be short and efficient, because it will happen very often.