R Records
R Records

Reputation: 17

How to replace duplicated IDs with a new id?

Say I have this table:

ID | Name
1  | Daniel
2  | Michael
1  | Lawrence

How can I via query find all the duplicated IDs and replace the other one with a new unique number, so that there are no longer duplicates?

Upvotes: 0

Views: 578

Answers (1)

Luigi di Massa
Luigi di Massa

Reputation: 41

The simplest way is to drop the id column and re add the column as primary key autoincrement:

ALTER TABLE tableName DROP idColumnName;

and than

ALTER TABLE tableName ADD idColumnNameint NOT NULL PRIMARY KEY AUTO_INCREMENT;

Upvotes: 1

Related Questions