创建日期和上次修改日期触发器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了创建日期和上次修改日期触发器相关的知识,希望对你有一定的参考价值。

First, create two new fields in your table "Created", and "LastModified" as "datetime" fields, being sure to allow nulls. Then run this code as a query to create triggers that will update the appropriate field when a record is modified, or a record is inserted. This proves very useful when you're dealing with a huge database.

In the code below replace [TableName] with your actual table name, and replace [UniqueID] with a unique ID field name in your table.
  1. CREATE TRIGGER tr[TableName]CreateDate ON [TableName]
  2. FOR INSERT
  3. AS
  4. UPDATE [TableName] SET [TableName].Created=getdate()
  5. FROM [TableName] INNER JOIN Inserted ON [TableName].[UniqueID]= Inserted.[UniqueID]
  6.  
  7. GO
  8.  
  9. CREATE TRIGGER tr[TableName]LastModifiedDate ON [TableName]
  10. FOR UPDATE
  11. AS
  12. UPDATE [TableName] SET [TableName].LastModified=getdate()
  13. FROM [TableName] INNER JOIN Inserted ON [TableName].[UniqueID]= Inserted.[UniqueID]

以上是关于创建日期和上次修改日期触发器的主要内容,如果未能解决你的问题,请参考以下文章

国家和年份 - 上次修改日期

日期 mysql 的创建日期和上次更新日期

NSFileManager OS X 上次修改日期

SharePoint 上次修改日期和匿名访问

如何在 MS Azure 中为我的 blob 存储中的 blob 提取上次修改日期

Hive - 如何在 Hive 中跟踪和更新增量表的上次修改日期?