/ Published in: SQL

ms sql triggers for automatic Create and LastModified Dates
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* <TableName> - Name of the selected table <UniqueId> - Primary Key of the selected table */ CREATE TRIGGER tr<TableName>CreateDate ON <TableName> FOR INSERT AS UPDATE <TableName> SET <TableName>.Created=getdate() FROM <TableName> INNER JOIN Inserted ON <TableName>.<UniqueId> = Inserted.<UniqueId> GO CREATE TRIGGER tr<TableName>LastModifiedDate ON <TableName> FOR UPDATE AS UPDATE <TableName> SET <TableName>.LastModified=getdate() FROM <TableName> INNER JOIN Inserted ON <TableName>.<UniqueId> = Inserted.<UniqueId> GO
Comments
