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?
问问题
40419 次
3 回答
12
您只能将列定义AUTO_INCREMENT
为 aPRIMARY KEY
和 an INT
(不确定,但 BIGINT 也可以)。既然你想SerialNo
将 设置为AUTO_INCREMENT
,为什么不将其设置为PRIMARY KEY
和?EnrollmentID
UNIQUE
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
(
id
int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
first_name
varchar(100) NOT NULL,
last_name
varchar(100) NOT NULL,
gender
varchar(30) NOT NULL,
email
varchar(200) NOT NULL,
password
varchar(200) NOT NULL,
address
text NOT NULL,
mobile_no
varchar(15) NOT NULL ) 引擎=InnoDB 默认字符集=latin1;
于 2022-02-03T15:30:16.247 回答