mysql - adding a primary key to a large table

advertisements

Have a large table here with no primary key and im trying to add a column called "id" at the beginning of the table. Im using phpMyAdmin but cant figure it out. Its easy enuff to add a column, but how do u set up the auto-increment feature to automatically assign a key to each row? Any suggestions???


Use:

ALTER TABLE `tablename` ADD `FIELDNAME` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST

In phpmyadmin (depending on your version) set the checkbox on AI (auto_increment) and the index on primary. The result is a SQL as postet above.