Home » RDBMS Server » Server Administration » Duplicate Unique Key
Duplicate Unique Key [message #53478] Mon, 23 September 2002 12:17 Go to next message
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 #53482 is a reply to message #53478] Mon, 23 September 2002 13:22 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
http://orafaq.net/faqsql.htm#ONLOGON
Re: Duplicate Unique Key [message #53486 is a reply to message #53478] Mon, 23 September 2002 14:14 Go to previous message
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

Previous Topic: Sequence number update
Next Topic: Oracle 9i R2 memory configuration
Goto Forum:
  


Current Time: Fri Sep 20 01:51:28 CDT 2024