PHP ZCE mock test, interview preparation, daily lessons under chalk talk

Sunday, March 17, 2013

Mysql - alter a table column to make it auto increment

Mysql : alter a table to make one of its column auto increment.


Query :




mysql> ALTER TABLE  WAREHOUSE MODIFY COLUMN WarehouseId INT(11) AUTO_INCREMENT;
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key



i.e. in order to define a column as auto increment it must be set as primary key.

mysql> ALTER TABLE  WAREHOUSE MODIFY COLUMN WarehouseId INT(11) AUTO_INCREMENT PRIMARY KEY;

Query OK, 0 rows affected (0.15 sec)
Records: 0  Duplicates: 0  Warnings: 0





No comments:

Post a Comment