Mysql primary key after creating and using a database: Difference between revisions

From D3xt3r01.tk
Jump to navigationJump to search
(New page: ==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...)
 
(No difference)

Latest revision as of 23:28, 25 June 2009

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 .. :)