Ed White
2009-03-26 16:25:02 UTC
I have a table set up where the primary key is a DateTime field. According
to the SQL Server documention, the DateTime field can store data with up to 3
digits representing fractional seconds. The problem I'm having is that if I
have two dates that are the exactly the same except for one millisecond, SQL
Server is treating them as the same date and I'm getting a 'cannot insert
duplicate key' violation. For example, these two dates should be different
2009-03-26 08:57:55.843
2009-03-26 08:57:55.844 (the last digit is different)
but SQL Server gives me a 'cannot insert duplicate key' if I try to enter
rows with those two dates in them.
However, if in SSMS I manually enter the second date as
2009-03-26 08:57:55.845
SQL Server changes it to
2009-03-26 08:57:55.847
and does not give a primary key violation.
So apparently, SQL Server's DateTime is not accurate to milleseconds, but
maybe accurate to 4 milliseconds. Is this correct? Is there a way to get
around this? (And yes, I need the dates to be that precise).
to the SQL Server documention, the DateTime field can store data with up to 3
digits representing fractional seconds. The problem I'm having is that if I
have two dates that are the exactly the same except for one millisecond, SQL
Server is treating them as the same date and I'm getting a 'cannot insert
duplicate key' violation. For example, these two dates should be different
2009-03-26 08:57:55.843
2009-03-26 08:57:55.844 (the last digit is different)
but SQL Server gives me a 'cannot insert duplicate key' if I try to enter
rows with those two dates in them.
However, if in SSMS I manually enter the second date as
2009-03-26 08:57:55.845
SQL Server changes it to
2009-03-26 08:57:55.847
and does not give a primary key violation.
So apparently, SQL Server's DateTime is not accurate to milleseconds, but
maybe accurate to 4 milliseconds. Is this correct? Is there a way to get
around this? (And yes, I need the dates to be that precise).