自动增量字段给出错误

时间:2014-09-05 07:47:46

标签: php mysql

如果在mysql中已经定义了其他字段,如何使列自动递增? 错误

SQL查询:

ALTER TABLE `registration` ADD `rid` INT NOT NULL AUTO_INCREMENT FIRST ,
ADD PRIMARY KEY ( `rid` )

MySQL说:文档

#1068 - Multiple primary key defined 

这是ddl

Field   Type    Collation   Attributes  Null    Default     Extra   Action
rname   varchar(255)    latin1_swedish_ci       No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
rmobile     varchar(255)    latin1_swedish_ci       No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
first_name  varchar(37)     latin1_swedish_ci       No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
last_name   varchar(27)     latin1_swedish_ci       No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
date_of_birth   varchar(45)     latin1_swedish_ci       No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
address     varchar(200)    latin1_swedish_ci       No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
city    varchar(150)    latin1_swedish_ci       No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
state   varchar(200)    latin1_swedish_ci       No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
postal_code     varchar(67)     latin1_swedish_ci       No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
mobile_no   varchar(18)     latin1_swedish_ci       No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
email_id    varchar(99)     latin1_swedish_ci       No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
password    varchar(25)     latin1_swedish_ci       No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
payment     bigint(50)          No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
pay     tinyint(1)          No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
status  tinyint(1)          No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
dt  timestamp           Yes     NULL        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext

1 个答案:

答案 0 :(得分:-1)

如错误所述,表中已有主键,并且表中不能有两列作为主键。所以让你新的列UNIQUE而不是PK:

ALTER TABLE `registration` ADD `rid` INT NOT NULL AUTO_INCREMENT UNIQUE