Posted By

simondiercks on 03/30/10


Tagged

mysql table auto add increment alter


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

virendrakryadav


add auto-imcremented column to existing table without ex- and reimporting


 / Published in: MySQL
 

How to add an auto-incremented column to an existing table without ex- and reimporting.

  1. ALTER TABLE t1, change id id INT (11) DEFAULT '0' NOT NULL, DROP PRIMARY KEY;
  2. ALTER TABLE table ADD id2 INT UNSIGNED NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY (id2);
  3. ALTER TABLE t1, change id2 id2 INT (10) NULL, DROP PRIMARY KEY;
  4. ALTER TABLE t1, change id id INT (11)UNSIGNED DEFAULT '0' NOT NULL AUTO_INCREMENT, add PRIMARY KEY(id);

Report this snippet  

You need to login to post a comment.