SQL Server 2008 timestamp data type

2019-08-28 05:52发布

At present I have a column with datatype datetime with default constraint. Now I want to alter as a data type as time stamp.

alter table tblname
alter column date_modified timestamp not null

My original requirement is whenever I update a record the column called date_modified should update with recent time .

This is same functionality which is working in MYSQL with datatype TIMESTAMP and default value CURRENT_TIMESTAMP

How can I perform in this in SQL Server 2008??

2条回答
乱世女痞
2楼-- · 2019-08-28 05:58

Did you check what the TIMESTAMP type actually is in SQL Server? It's different from the TIMESTAMP type in mysql. The documentation says:

Is a data type that exposes automatically generated, unique binary numbers within a database

So there's no way to set it to "the current time"

查看更多
甜甜的少女心
3楼-- · 2019-08-28 06:18

Timestamp in MySQL and timestamp in SQL Server is not the same thing. Keep your datetimeand add an after update trigger that updates date_modified with getdate().

查看更多
登录 后发表回答