Results 1 to 9 of 9

Thread: Duplicates problem in datetime field, help!!

  1. #1
    Join Date
    Jan 2003
    Posts
    58

    Duplicates problem in datetime field, help!!

    I have a table with a 'datetime' column. I need to make this as the Primary Key. But, currently there are lot of duplicates in this datetime column, which is not allowing me to make it as PK. How do I update the data in this field which makes it unique in all the rows, at the same time the date part remains same as old.
    Probably, I need to add few milliseconds of 'time' for each row in an increasing fashion, like 1 ms to 1st row, 2 ms to 2nd row, 3 ms to 3rd row etc..?
    There are million rows in the table, only 1000 of them are duplicates. Any help?

  2. #2
    Join Date
    Aug 2004
    Location
    India
    Posts
    5
    Well, I believe its always better to keep some numeric column as PK and make the date field unique. You can always remove the duplicate rows.

    Regards

  3. #3
    Join Date
    Jan 2003
    Posts
    58
    I need to keep this as part of a composite PK. I can't avoid it..so someone please help me clean up existing data. I can't delete the dups but I should update the date field by few milliseconds so as to make them unique.

  4. #4
    Join Date
    Jan 2003
    Posts
    58
    Anyone to help??

  5. #5
    Join Date
    Feb 2003
    Posts
    1,048
    Updating the data to make it unique would be a bad way to go. Either it is not the right field to use as part of a composite primary key or you need to add an additional field to the primary key.

  6. #6
    Join Date
    Jan 2003
    Posts
    58
    Yeah, but I have to do it this way to fix the existing data. There is no other choice of columns. Any Gurus to help update the data?

  7. #7
    Join Date
    Feb 2003
    Posts
    1,048
    Query for the duplicates. Add 1 millisecond to one of each duplicate and keep looping through until all duplicates are gone.

  8. #8
    Join Date
    Aug 2004
    Location
    USA
    Posts
    80
    looks like a good idea..can you give me the example code?

  9. #9
    Join Date
    Jan 2003
    Posts
    58
    Thanks Rawhide,

    I will try that.

Posting Permissions

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