运行 UPDATE 时... datetime = NOW(); 所有更新的行都具有相同的日期/时间吗?
当您运行类似以下内容时:
UPDATE table SET datetime = NOW();
在包含 1 000 000 000 条记录的表上,并且查询需要 10 秒才能运行,所有行是否具有完全相同的时间(分钟和秒)还是具有不同的时间? 换句话说,时间是查询开始时还是每行更新时?
我正在运行 MySQL,但我认为这适用于所有数据库。
When you run something similar to:
UPDATE table SET datetime = NOW();
on a table with 1 000 000 000 records and the query takes 10 seconds to run, will all the rows have the exact same time (minutes and seconds) or will they have different times? In other words, will the time be when the query started or when each row is updated?
I'm running MySQL, but I'm thinking this applies to all dbs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
http://dev.mysql.com /doc/refman/5.0/en/date-and-time-functions.html#function_now
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_now
将
NOW()
分配给变量,然后用变量更新日期时间:现在像这样更新
,根据您的要求纠正语法
Assign
NOW()
to a variable then update the datetime with variable:now update like this
correct the syntax, as per your requirement
它们应该具有相同的时间,更新应该是原子的,这意味着无论执行需要多长时间,操作都应该发生,就好像所有操作都是同时完成的一样。
如果您遇到不同的行为,那么是时候更换另一个 DBMS 了。
They should have the same time, the update is supposed to be atomic, meaning that whatever how long it takes to perform, the action is supposed to occurs as if all was done at the same time.
If you're experiencing a different behaviour, it's time to change for another DBMS.
sqlite 的答案是
为了以防万一其他人正在寻找它。
The sqlite answer is
in case someone else was looking for it.