How to create a automatically generated timestamp column in table in Microsoft SQL Server 2019? Timestamp column should be automatically generated when I insert or update table.
In IBM Db2 database the syntax is the following:
create table myschema.mytable (col1 int, col2 timestamp not null generated always for each row on update as row change timestamp
insert into myschema.mytable (col1) values (1)
update myschema.mytable set col1 = 2
After insert
/update
of column col1
, column col2
is automatically generated as current timestamp.
mycolumn datetime not null default(current_timestamp)
rowversion
) you either need a trigger, or to run your update through a SP which adds it. There is no automated way other thanrowversion
.