Collections:
Verify Time Precision in SQL Server Transact-SQL
How to verify the precession of the server system time in SQL Server Transact-SQL?
✍: FYIcenter.com
You can run a WHILE loop to check the precision of server system time
in Transact-SQL as shown below:
DECLARE @var DATETIME2(7);
DECLARE @count INT = 0;
WHILE @count<100 BEGIN
SET @count = @count + 1;
SET @var = SYSDATETIME();
PRINT CAST(@count AS CHAR(3))+': '
+CAST(CAST(@var AS TIME(7)) AS CHAR(16));
END
---------------------
1 : 19:39:22.3348095
2 : 19:39:22.3348095
...
13 : 19:39:22.3348095
14 : 19:39:22.3358096
15 : 19:39:22.3358096
...
78 : 19:39:22.3358096
79 : 19:39:22.3968131
80 : 19:39:22.3968131
...
100: 19:39:22.3968131
As you can see from the output, the actual precision of the SYSDATETIME() function is very poor, about 0.001 second. This is much lower than 0.0000001 second of what SYSDATETIME() can return.
There are 3 main factors affecting the actual precision of the SYSDATETIME() function:
⇒ Adding and Removing Days on Date and Time Values in SQL Server
⇐ Get System Date and Time in SQL Server Transact-SQL
⇑ Date/Time Operations and Functions in SQL Server Transact-SQL
2017-02-22, 2477🔥, 0💬
Popular Posts:
What Are Out-of-Range Errors with DATETIME values in SQL Server Transact-SQL? When you enter DATETIM...
How To Use GO Command in "sqlcmd" in SQL Server? "sqlcmd" is a command line client application to ru...
Where to find tutorials to answer some frequently asked questions on Microsoft SQL Server Transact-S...
What is dba.FYIcenter.com Website about? dba.FYIcenter.com is a Website for DBAs (database administr...
How To Get a List of All Tables with "sys.tables" View in SQL Server? If you want to see the table y...