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

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -