Mysql primary key after creating and using a database

From D3xt3r01.tk
Revision as of 23:28, 25 June 2009 by Admin (talk | contribs) (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...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 .. :)