11

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?

4

3 回答 3

12

您只能将列定义AUTO_INCREMENT为 aPRIMARY KEY和 an INT 不确定,但 BIGINT 也可以。既然你想SerialNo将 设置为AUTO_INCREMENT,为什么不将其设置为PRIMARY KEY和?EnrollmentIDUNIQUE

CREATE TABLE TableName
(
    SerialNo INT AUTO_INCREMENT PRIMARY KEY,
    EnrollmentID INT UNIQUE,
    -- other columns...
)
于 2013-07-13T19:22:47.473 回答
4

确保将序列号列定义为UNIQUE

于 2013-07-13T19:17:37.730 回答
0

CREATE TABLE tbl_login( idint(11) NOT NULL AUTO_INCREMENT PRIMARY KEY , first_namevarchar(100) NOT NULL, last_namevarchar(100) NOT NULL, gendervarchar(30) NOT NULL, emailvarchar(200) NOT NULL, passwordvarchar(200) NOT NULL, addresstext NOT NULL, mobile_novarchar(15) NOT NULL ) 引擎=InnoDB 默认字符集=latin1;

于 2022-02-03T15:30:16.247 回答