Retrieving date in sql server, CURRENT_TIMESTAMP vs GetDate()

▼魔方 西西 提交于 2019-11-26 11:04:38

问题


Using SQL Server - which is the fastest or best practice method to use for date retrieval? Is there a difference?


回答1:


CURRENT_TIMESTAMP is standard ANSI SQL, and so is theoretically one tiny little island of 'don't need to change' amongst your thousands of SQL Server-specific lines of SQL if you ever need to move databases....




回答2:


CURRENT_TIMESTAMP is part of the ANSI SQL spec. GETDATE() is a SQL Server-specific function inherited from the original Sybase code on which SQL Server is based.

They do exactly the same thing, though.




回答3:


My vote is for CURRENT_TIMESTAMP for 'portability' reasons i.e. why be SQL Server -specific when there is a direct SQL-92 equivalent?

PS why was it not named getdatetime()? Now that SQL Server 2008 has a DATE and TIME data type, we can hope to get support for SQL-92's CURRENT_DATE and CURRENT_TIME, at which point getdate() could be potentially even more confusing.




回答4:


Books Online tells us that CURRENT_TIMESTAMP "is equivalent to GETDATE()".



来源:https://stackoverflow.com/questions/186572/retrieving-date-in-sql-server-current-timestamp-vs-getdate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!