SQL precision getdate?

I am experimenting with a program that inserts data into a SQL Server 2005 database (on XP SP3) at high speed. (This is for collecting synchronization data, so I can evaluate various aspects of my design).

My basic setup involves inserting data into a table as follows (and using SP, which simply indicates the payload field):

create table data
(
 Id int  PRIMARY KEY Identity,
 payload datatime not null,
 inserted datetime default (getdate()) not null
)

Note that both datetime fields also have UNIQUE constraints.

In the client program, I called SP in such a closed loop that I had problems with the accuracy of the .Net DateTime.Now value (and possibly the sleeping layer), and, therefore, violating the unique payload limitation. I turned to the combination of the stopwatch variable, Thread.Sleep () bit and manually created the “payload” data so that it would not violate the resolution of the SQL DateTime field (3.3 ms)

However, when inserts are generated at a speed of 5 ms to 10 ms, I began to see problems with the "Insert" field on the SQL side, where the row is regularly discarded for a unique key violation. Only when I slow down the insertion speed to more than 15 or so does this problem go away. This metric is suspiciously similar to the accuracy problem I had with .Net DateTime.Now (I read 16ms in place somewhere), so I'm wondering what the actual accuracy of the Getdate () SQL function is.

So can someone tell me what GetDate () supports, and will it be bound to the same source as the .Net DateTime.Now value? And what accuracy should I expect from him?

As an aside, I know about the DATETIME2 type on the SQL 2008 server, so the question arises as to what accuracy for GetDate () on this system also.

+3
2

DATETIME 3,3 , GETDATE() , , . MSDN / /, , /.

+2

DATETIME 2 . , , ( ), 1/300 , 3,3 .

declare @d  varchar(24)

while 1=1 
begin
set @d=CONVERT(VARCHAR(24), GETDATE(), 113)
raiserror('%s',0,1, @d) with nowait
end

, , , - , .

01 Aug 2010 00:56:53:913
...
01 Aug 2010 00:56:53:913
01 Aug 2010 00:56:53:917
...
01 Aug 2010 00:56:53:917
01 Aug 2010 00:56:53:920
...
01 Aug 2010 00:56:53:920
01 Aug 2010 00:56:53:923

GetDate() SQL Server 2008, , SQL2005. sysdatetime . .

SET NOCOUNT ON

CREATE TABLE #DT2(
[D1] [datetime2](7) DEFAULT (getdate()),    
[D2] [datetime2](7) DEFAULT (sysdatetime())
) 
GO

INSERT INTO #DT2
          DEFAULT  VALUES
GO 100

SELECT DISTINCT [D1],[D2],DATEDIFF(MICROSECOND, [D1], [D2]) AS MS
 FROM #DT2

D1                           D2                              MS
----------------------------    -----------------------      ------
2010-08-01 18:45:26.0570000   2010-08-01 18:45:26.0625000     5500
2010-08-01 18:45:26.0600000   2010-08-01 18:45:26.0625000     2500
2010-08-01 18:45:26.0630000   2010-08-01 18:45:26.0625000     -500
2010-08-01 18:45:26.0630000   2010-08-01 18:45:26.0781250     15125
2010-08-01 18:45:26.0670000   2010-08-01 18:45:26.0781250     11125
2010-08-01 18:45:26.0700000   2010-08-01 18:45:26.0781250     8125
+1

All Articles