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

I have a database table, but without an index, and I want to add an id index to this table, what will be uniqe for each row, how can I do this with mysql?

+4
source share
1 answer

Assuming you don't have a key in the table, you can do this:

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

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

+11
source

Source: https://habr.com/ru/post/1399413/


All Articles