2014-09-05 76 views
0

如何使列自動增量,如果其他字段是在alresdy定義在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

向我們顯示ddl表'註冊'。 – 2014-09-05 07:49:59

回答

-1

由於錯誤狀態,你已經在主鍵表,並且不能將兩列作爲表中的主鍵。所以,讓你新的專欄UNIQUE,而不是一個PK:

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