Duplicate Unique Key [message #53478] |
Mon, 23 September 2002 12:17 |
Nobby
Messages: 2 Registered: September 2002
|
Junior Member |
|
|
Just had to insert some data and it failed because of a duplicate key. The data had to go in so, I disabled the constraint but, this needs to be re-enabled. Does anybody know how to search for duplicate keys within a table. I need to adjust this and re-enable v.soon.
Cheers
|
|
|
|
Re: Duplicate Unique Key [message #53486 is a reply to message #53478] |
Mon, 23 September 2002 14:14 |
Trifon Anguelov
Messages: 514 Registered: June 2002
|
Senior Member |
|
|
Here is a script to do that:
SELECT min(id), max(id)
FROM table_name
WHERE your_rules_here
group by all_the_duplicate_columns_listed
having count(*) > 1;
Then choose to keep either the min(id) or max(id) and delete the rest of it.
Hope that helps,
clio_usa
OCP - DBA
Visit our Web site
|
|
|