sql server - T-SQL how to create a update trigger to update a column after a row is updated? -
i have table below. , want update [updatetime] column automatically when row's [content] column update.
create table [dbo].[filecontent] ( [fileid] int not null primary key, [content] nvarchar(max) not null , [updatetime] datetime not null default getdate() )
what's best way write trigger?
use this.
for more information triggers refer link.
create trigger sample on [dbo].[filecontent] update begin if update([content]) begin declare @nfieldid int select @nfieldid = [fileid] inserted update [dbo].[filecontent] set [updatetime] = getdate() [fileid] = @nfieldid end end
Comments
Post a Comment