SQL sqlserver 中日期时间和时间戳的区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7105093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 11:44:20  来源:igfitidea点击:

Difference between datetime and timestamp in sqlserver?

sqlsql-serverdatetime

提问by MduSenthil

What is the difference between Timestampand DatetimeSQL Server?

TimestampDatetimeSQL Server 有什么区别?

I thought Both formats are capable of storing date + time. Then, Where the difference is lying between them?

我认为这两种格式都能够存储日期 + 时间。那么,它们之间的区别在哪里呢?

But Timestampis not capable of storing date, time information.

Timestamp不能存储日期、时间信息。

Still Whats the difference?

还是有什么区别?

回答by Jon Skeet

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

根据文档timestamp是 的同义词rowversion- 它是自动生成的并保证1是唯一的。datetime不是 - 它只是一种处理日期和时间的数据类型,并且可以在插入等时由客户端指定。



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

1当然,前提是你使用得当。看评论。

回答by Andreas ?gren

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.

时间戳是一种行版本控制方法。实际上,在 sql server 2008 中,此列类型已重命名(即不推荐使用时间戳)为 rowversion。它基本上意味着每次更改一行时,该值都会增加。这是通过数据库计数器完成的,该计数器为每个插入或更新的行自动增加。

For more information:

想要查询更多的信息:

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

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

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

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