MySQL中的SYSDATE(),NOW(),CURRENT_TIMESTAMP,CURRENT_TIMESTAMP()之间的区别?

时间:2022-08-13 10:00:14

As per my knowledge,

据我所知,

SYSDATE(),
NOW(),
CURRENT_TIMESTAMP, and
CURRENT_TIMESTAMP() 

in MySQL are synonyms for one another. They all returns same value,then why MySQL provides all of them ? Are there different scenarios where I can use specific one of them ?

在MySQL中是彼此的同义词。它们都返回相同的值,然后为什么MySQL提供所有这些值?是否有不同的场景我可以使用其中一个?

2 个解决方案

#1


10  

They aren't all synonymous.

它们并非都是同义词。

SYSDATE() is different than NOW(), in a significant way. As a demonstration:

SYSDATE()与NOW()有很大不同。作为示范:

SELECT NOW(), SYSDATE(), SLEEP(5), NOW(), SYSDATE()

The output might look like this:

输出可能如下所示:

2018-03-01 11:09:19   2018-03-01 11:09:19   0   2018-03-01 11:09:19   2018-03-01 11:09:24

So, yes, there are specific scenarios where you might want to use SYSDATE() rather than NOW().

所以,是的,有些特定场景可能需要使用SYSDATE()而不是NOW()。

MySQL does provides several functions that can return the same result

MySQL确实提供了几个可以返回相同结果的函数

DATE(NOW()) vs. CURRDATE()

日期(现在())与CURRDATE()

I suspect that this is large part due to a desire to make transition from other Relational DBMS easier, by more closely matching (where possible and appropriate) the function names and syntax used by Oracle, SQL Server, and so on.

我怀疑这很大程度上是由于希望通过更紧密地匹配(在可能和适当的情况下)Oracle,SQL Server等使用的函数名称和语法,从而更容易从其他Relational DBMS转换。

#2


7  

After reading http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_current-timestamp document, concluded that :

在阅读http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_current-timestamp文档后,得出结论:

NOW() returns a constant time that indicates the time at which the statement began to execute. NOW() returns the time at which the function or triggering statement began to execute, but SYSDATE() returns the exact time at which it executes.

NOW()返回一个常量时间,指示语句开始执行的时间。 NOW()返回函数或触发语句开始执行的时间,但SYSDATE()返回它执行的确切时间。

And CURRENT_TIMESTAMP, CURRENT_TIMESTAMP() are synonyms for NOW().

CURRENT_TIMESTAMP,CURRENT_TIMESTAMP()是NOW()的同义词。

#1


10  

They aren't all synonymous.

它们并非都是同义词。

SYSDATE() is different than NOW(), in a significant way. As a demonstration:

SYSDATE()与NOW()有很大不同。作为示范:

SELECT NOW(), SYSDATE(), SLEEP(5), NOW(), SYSDATE()

The output might look like this:

输出可能如下所示:

2018-03-01 11:09:19   2018-03-01 11:09:19   0   2018-03-01 11:09:19   2018-03-01 11:09:24

So, yes, there are specific scenarios where you might want to use SYSDATE() rather than NOW().

所以,是的,有些特定场景可能需要使用SYSDATE()而不是NOW()。

MySQL does provides several functions that can return the same result

MySQL确实提供了几个可以返回相同结果的函数

DATE(NOW()) vs. CURRDATE()

日期(现在())与CURRDATE()

I suspect that this is large part due to a desire to make transition from other Relational DBMS easier, by more closely matching (where possible and appropriate) the function names and syntax used by Oracle, SQL Server, and so on.

我怀疑这很大程度上是由于希望通过更紧密地匹配(在可能和适当的情况下)Oracle,SQL Server等使用的函数名称和语法,从而更容易从其他Relational DBMS转换。

#2


7  

After reading http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_current-timestamp document, concluded that :

在阅读http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_current-timestamp文档后,得出结论:

NOW() returns a constant time that indicates the time at which the statement began to execute. NOW() returns the time at which the function or triggering statement began to execute, but SYSDATE() returns the exact time at which it executes.

NOW()返回一个常量时间,指示语句开始执行的时间。 NOW()返回函数或触发语句开始执行的时间,但SYSDATE()返回它执行的确切时间。

And CURRENT_TIMESTAMP, CURRENT_TIMESTAMP() are synonyms for NOW().

CURRENT_TIMESTAMP,CURRENT_TIMESTAMP()是NOW()的同义词。