简体   繁体   中英

#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key

I have a serial no. column which is auto increment, but I want enrollment id. to be the primary key and MySQL is just not allowing me to do that. Is there any way around to do that?

"

You can only define a column as AUTO_INCREMENT if it is a PRIMARY KEY and an INT ( not sure of this but BIGINT will work too ) . Since you want the SerialNo to be set as AUTO_INCREMENT , why not make it as PRIMARY KEY and the EnrollmentID as UNIQUE ?

CREATE TABLE TableName
(
    SerialNo INT AUTO_INCREMENT PRIMARY KEY,
    EnrollmentID INT UNIQUE,
    -- other columns...
)

确保将序列号列定义为UNIQUE

CREATE TABLE tbl_login<\/code> ( id<\/code> int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY , first_name<\/code> varchar(100) NOT NULL, last_name<\/code> varchar(100) NOT NULL, gender<\/code> varchar(30) NOT NULL, email<\/code> varchar(200) NOT NULL, password<\/code> varchar( 200) 非空, address<\/code>文本非空, mobile_no<\/code> varchar(15) 非空) ENGINE=InnoDB DEFAULT CHARSET=latin1;

"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM