How to change a primary key in SQL to auto_increment?

Posted by Jian Lin on Stack Overflow See other posts from Stack Overflow or by Jian Lin
Published on 2010-04-24T11:50:22Z Indexed on 2010/04/24 11:53 UTC
Read the original article Hit count: 224

I have a table in MySQL that has a primary key:

mysql> desc gifts;
+---------------+-------------+------+-----+---------+-------+
| Field         | Type        | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| giftID        | int(11)     | NO   | PRI | NULL    |       |
| name          | varchar(80) | YES  |     | NULL    |       |
| filename      | varchar(80) | YES  |     | NULL    |       |
| effectiveTime | datetime    | YES  |     | NULL    |       |
+---------------+-------------+------+-----+---------+-------+

but I wanted to make it auto_increment.

The following statement failed. How can it be modified so that it can work? thanks

mysql> alter table gifts modify giftID int primary key auto_increment;
ERROR 1068 (42000): Multiple primary key defined

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql