如何添加触发器以填充ModifiedDate

时间:2016-11-09 15:47:24

标签: tsql triggers last-modified

当行更新/更改时,是否可以使用CurrentDateTime自动更新ModifiedDate?

SELECT [ID]
      ,[PK]
      ,[Iteration]
      ,[Exam01]
      ,[Exam02]
      ,[Exam03]
      ,[Exam04]
      ,[Exam05]
      ,[Exam06]
      ,[Exam07]
      ,[Exam08]
      ,[Exam09]
      ,[Exam10]
      ,[Exam11]
      ,[Exam12]
      ,[Exam13]
      ,[Exam14]
      ,[HRGCode]
      ,[AgeStart]
      ,[AgeEnd]
      ,[CreateDate]
      ,[ModifiedDate] --- Need this to update when the row is Modified!
      ,[ModifiedBy]
      ,[Comments]
  FROM [CommDB].[dbo].[tblRadiologyNucMedLookup] c
  order by ID

1 个答案:

答案 0 :(得分:1)

你真的需要一个触发器吗?您可以在与

相同的UPDATE语句中添加该列
update tblRadiologyNucMedLookup 
set Iteration = 10,
[ModifiedDate] = getdate()
where ID = 101;