#1075 - 表定义不正确;只能有一个自动列,并且必须将其定义为键 [英] #1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key

查看:33
本文介绍了#1075 - 表定义不正确;只能有一个自动列,并且必须将其定义为键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个序列号.自动增量列,但我想要注册 ID.成为主键,而 MySQL 只是不允许我这样做.有没有办法做到这一点?

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?

推荐答案

您只能将列定义为 AUTO_INCREMENT 如果它是 PRIMARY KEYINT (不确定,但 BIGINT 也可以使用).既然您希望将 SerialNo 设置为 AUTO_INCREMENT,为什么不将其设置为 PRIMARY KEY 并将 EnrollmentID 设置为唯一?

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...
)

这篇关于#1075 - 表定义不正确;只能有一个自动列,并且必须将其定义为键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆