jcubic
jcubic

Reputation: 66650

Is it possible to add new unique index to the existing database table?

I have database table but without the index, and I want to add index id to that table, that will be uniqe for each row, how can I do this using mysql?

Upvotes: 4

Views: 439

Answers (1)

DarkAjax
DarkAjax

Reputation: 16223

Assuming you don't have a key on the table already you can do this:

ALTER TABLE whatever ADD id Int NOT NULL AUTO_INCREMENT PRIMARY KEY;

And remember you can add FIRST to the end of that line to make it the first column which would be a good idea for an id.

Upvotes: 11

Related Questions