Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between datetime and timestamp in sqlserver? [duplicate]

People also ask

What is the difference between datetime and TIMESTAMP in SQL Server?

Timestamp is a synonym for rowversion, according to the documentation, and it's created automatically and guaranteed1 to be unique. Datetime isn't one of them; it's merely a data type that handles dates and times and may be customised by the client on insert, for example.

What is the difference between date and datetime in SQL Server?

The DATE type is used for values with a date part but no time part. MySQL retrieves and displays DATE values in ' YYYY-MM-DD ' format. The supported range is '1000-01-01' to '9999-12-31' . The DATETIME type is used for values that contain both date and time parts.

What is the difference between time and TIMESTAMP?

TIMESTAMP: It is also used for values that contain both date and time parts, and includes the time zone. TIMESTAMP has a range of 1970-01-01 00:00:01 UTC to 2038-01-19 03:14:07 UTC. TIME: Its values are in HH:MM:SS format (or HHH:MM:SS format for large hours values). TIME values may range from -838:59:59 to 838:59:59 .

What is the alternative of TIMESTAMP in SQL Server?

In DDL statements, use rowversion instead of timestamp wherever possible. For more information, see Data Type Synonyms (Transact-SQL).


According to the documentation, timestamp is a synonym for rowversion - it's automatically generated and guaranteed1 to be unique. datetime isn't - it's just a data type which handles dates and times, and can be client-specified on insert etc.


1 Assuming you use it properly, of course. See comments.


Datetime is a datatype.

Timestamp is a method for row versioning. In fact, in sql server 2008 this column type was renamed (i.e. timestamp is deprecated) to rowversion. It basically means that every time a row is changed, this value is increased. This is done with a database counter which automatically increase for every inserted or updated row.

For more information:

http://www.sqlteam.com/article/timestamps-vs-datetime-data-types

http://msdn.microsoft.com/en-us/library/ms182776.aspx