开发者

How to read system time in WPF for updating SQL Server timestamp field?

开发者 https://www.devze.com 2022-12-17 19:58 出处:网络
For the purpose of organizing streamlined database timer-based polling, with every updating of database table I need to update a timestamp field in a SQL Server 2008 database (the开发者_运维问答n poll

For the purpose of organizing streamlined database timer-based polling, with every updating of database table I need to update a timestamp field in a SQL Server 2008 database (the开发者_运维问答n poll, read its value, compare with the value in front-end and making decisions about reading the whole table).

Regarding all this, how I could read system time for writing timestamp? What data format of SQL Server field to use (DataTime or Time)? And how values of this format could be compared?


Are you talking about a database column of TIMESTAMP type??

Those are binary timestamp that SQL Server will update internally - they have nothing to do with date and/or time - it's just a binary-encoded counter, really. These fields are handled by the system, and they're reliable and very accurate - if you want to have some kind of an optimistic concurrency locking mechanism, use this field type.

If you want a DATETIME field containing a date and time of the last modification, you're best option would be to have a AFTER INSERT/AFTER UPDATE trigger on that table which sets the last updated column to the current date/time of the SQL Server automatically, without you having to do anything about it.

DATETIME in SQL Server 2005 is accurate to about 3.33ms - in SQL Server 2008, DATETIME2 can be made accurate to 100ns, if needed. As such, do not rely on a DATETIME column for 100% accurate checking whether something has changed or not! The 3.33ms accuracy might give misleading results!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号