Thursday, November 27, 2008

Key column information is insufficient or incorrect. Too many rows were affected by update.

In MS SQL 2000, in a table with no primary key/index/constraint, whenever there is duplicate record, we cannot delete any of the duplicate record, it will give this error:
"Key column information is insufficient or incorrect. Too many rows were
affected by update."

So how is the trick to remove this duplication?
I was searching and finally found something.

here's what we can do:
1. find out which are the duplicate records
SELECT col1, col2, count(*)
FROM t1
GROUP BY col1, col2
HAVING count(*) > 1

2. delete the duplicate by using this sql
set rowcount 1
delete from t1
where col1=1 and col2=1

it works!

Reference: here

No comments: