Mysql primary key after creating and using a database

From D3xt3r01.tk
Jump to navigationJump to search

WHY

.. I created a database .. used it for quite a while without a primary key .. ( I had a uniq field set as an index ) .. but .. I now need a primary key ..

HOW

Feel free to use your favorite cli/webbased mysql interface

ALTER TABLE `table_name` ADD `field_name` INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY(`field_name`);

Other stuff

Using PhpMyAdmin to do this was a problem because it wouldn't want to do both at the same time .. and you can't set one and expect the other one to work .. :)