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
Leave off the
primary keyattribute:Certain column attributes, such as
PRIMARY KEY, aren’t exactly properties of the column so much as shortcuts for other things. A column markedPRIMARY KEY, for example, is placed in thePRIMARYindex. Futhermore, all columns in thePRIMARYindex are given theNOT NULLattribute. (Aside: to have a multi-column primary key, you must use a separate constraint clause rather than multiplePRIMARY KEYcolumn attributes.) Since the column is already in thePRIMARYindex, you don’t need to specify it again when you modify the column. TrySHOW CREATE TABLE gifts;to see the affects of using thePRIMARY KEYattribute.