I have a table s_phone in this table there is column s_update.
I want to get the current date time every time I update or insert into this table
getdate() or systime() or CURRENT_TIMESTAMP get the date time when insert only not when update
You can use TRIGGER The trigger will be automatically run when insert/update happen in the table.
For example:
create table tbl1
(
col1 int primary key,
col2 datetime
)
go
create trigger trg01
on tbl1
for insert, update
as
begin
update tbl1
set col2 = GETDATE()
where col1 in (select col1 from inserted)
end
go
insert into tbl1(col1) values (1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With