Thursday, March 22, 2012

Deleting duplicate records

Hi All,
I am having one table named MyTable and this table contains only one column MyCol. Now i m having 10 records in it and all the records are duplicate ie value is 7 for all 10 records.

It is something like this,

MyCol
7
7
7
7
7
7
7
7
7
7

Now i m trying to delete 10th record or any record then it gives me error
"Key column information is insufficient or incorrect. Too many rows were affected by update."

What should i do if i want only 4 records insted 10 records in my table?
How do i delete the 6 records from table?

Plz help me.

Regards,
ShaileshSince there seems to be no (primary) key to identity the row there's nothing left than a workaround, which basically will delete all rows with, in this case, mycol on 7, and inserts four (your case) new records with the value 7.|||this could work for you:

set rowcount 4

delete from table_name

set rowcount 0 --set back to affect all rows

mojza|||Hi,
you can also temporary add one identity column and delete all the record that you dont need. After finish drop the new added identity column.

No comments:

Post a Comment