Results 1 to 2 of 2

Thread: another problem

  1. #1
    Join Date
    Dec 2002
    Posts
    2

    another problem

    i want to delete all of the duplicate records,but left one, how i can do?
    looking for your help

  2. #2
    Join Date
    Dec 2002
    Posts
    181
    Allen,
    It depends on which record you want to keep. If only the key column is duplicated (which should have been specified as the primary key in the table) and some other column differentiates the two, you should consider a manual review to see which record is correct. If however, the rows are true duplicates across all columns you can do the following:

    -- get only distinct records from table, put them into a temp table

    select distinct * into #temp from dup_table

    -- check your results, make sure everything looks kosher

    select * from #temp

    -- clear out the table and repopulte from the temp table

    truncate table dup_table
    go
    insert into dup_table
    select * from #temp


    Any foreign key constraints that reference the dup_table will need to be disabled until it has been repopulated.


    Jeff

Posting Permissions

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