Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 424
  • Last Modified:

Update trigger GetDate() on Indexed

I have a table with a DateTime field called "stamp".  The default value is already set for (GetDate()) on insert of new records and wrks fine.
I need that "stamp" field to get updated with GetDate() when that particular record/index is updated.

How can this be done.  I would prefer not to use any history/temp table method here.
0
H-SC
Asked:
H-SC
1 Solution
 
Aneesh RetnakaranDatabase AdministratorCommented:
create trigger tr_u_TableName
on table_name
after insert, update
as
 update t
 set datecolumn = GETDATE()
 from tableName t
 inner join inserted i on t.Primarykey = i.primarykey
0
 
H-SCAuthor Commented:
aneeshattingal,

Perfect!  Many thanks.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now