Results 1 to 8 of 8

Thread: milli-second update issue....

  1. #1
    Join Date
    Mar 2003
    Posts
    383

    milli-second update issue....

    Hello:

    I have a testing table table_1 with Key1 int as PK and dateField datetime default getutcdate as Alternative key

    select * from Table_1
    key1 dateField
    ----- -----------------------
    1 2007-03-26 21:13:53.163
    2 2007-03-26 21:13:56.913
    3 2007-03-26 21:14:04.117
    4 2007-03-26 21:14:05.320
    5 2007-03-26 21:14:08.193
    6 2007-03-26 21:14:08.647
    7 2007-03-26 21:14:09.397
    (7 row(s) affected)
    --testing if the millsecond are part of the unique key
    update Table_1 set dateField = '2007-03-26 21:14:08.194' where key1 = 6

    Msg 2601, Level 14, State 1, Line 1
    Cannot insert duplicate key row in object 'dbo.Table_1' with unique index 'AK1_Table_1'.
    The statement has been terminated.

    I think 2007-03-26 21:14:08.194 is a new value and is unique within the range of field. Why it is accepted at the insertion time while reject updating later?

    This verifies that:
    1. datatime field could be accurated to milli-second
    2. Guess there is a milli-second rounging issue.... thus could not be accurated to milli-second sometimes?

    thanks
    David

  2. #2
    Join Date
    Dec 2004
    Posts
    502
    Datetime values in SQL Server are rounded to every 3.33 milliseconds. Therefore, the datetime value of '2007-03-26 21:14:08.194' would be rounded to '2007-03-26 21:14:08.193' (the value where key1 = 5). If you change the value to '2007-03-26 21:14:08.195', this will get rounded to '2007-03-26 21:14:08.197', and you should then be able to complete the update.

  3. #3
    Join Date
    Mar 2003
    Posts
    383
    Hi "nosepicker":

    [Rounded to every 3.33 milliseconds].
    that probably explains why the last digit of milliseconds I could see will always be 0, 3 and 7 due to the 3.33 rounding mechanism.

    p.s. why some datetime field with the millisecond as .000, is there some 'switch' to turn the millisecond part active?

    thanks for the info.
    David

  4. #4
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    That may be because time portion was not specified when column was inserted or updated.

  5. #5
    Join Date
    Mar 2003
    Posts
    383
    Hello Skhanal:

    Thus, the milli-second portion is totally depended on the insert value, there is no 'switch' to turn on this portion.

    thanks for the info.
    David

  6. #6
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    Yes, sometimes you may only insert date value then time will be 12:00:00.000

  7. #7
    Join Date
    Mar 2003
    Posts
    383
    thanks again.
    -D

  8. #8
    Join Date
    Dec 2004
    Posts
    502
    Actually, if you insert only the date portion, the time will be 00:00:00.000 (12:00 AM), not 12:00:00.000 (which is 12:00 PM).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •