MySQL #1075 - 表定义不正确;只能有一个自动列,并且必须将其定义为键
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17633393/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
提问by Akash Gupta
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?
我有序列号 自动增量列,但我想要注册 ID。成为主键,而 MySQL 只是不允许我这样做。有没有办法做到这一点?
回答by John Woo
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
?
您只能将一列定义AUTO_INCREMENT
为 aPRIMARY KEY
和 an INT
(不确定,但 BIGINT 也可以)。既然您希望将 theSerialNo
设置为 as AUTO_INCREMENT
,为什么不将其设为 asPRIMARY KEY
和EnrollmentID
asUNIQUE
呢?
CREATE TABLE TableName
(
SerialNo INT AUTO_INCREMENT PRIMARY KEY,
EnrollmentID INT UNIQUE,
-- other columns...
)
回答by Niet the Dark Absol
Make sure you define your serial number column as UNIQUE
.
确保您将序列号列定义为UNIQUE
.