当前位置:网站首页>there can be only one auto column and it must be defined as a key
there can be only one auto column and it must be defined as a key
2022-06-23 22:11:00 【User 14527】
MySQL Auto increment of primary key and non primary key settings :
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
Start :
MySQL [liangcb]> show create table a5;
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------+ |
Table | Create Table
| +-------+-------------------------------------------------------------------------------------------------------------------------------------------------------+ | a5 | CREATE TABLE `a5` ( `id` int(11) DEFAULT NULL, `name` char(30) DEFAULT NULL, `id1` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 | +-------+-------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
MySQL [liangcb]> desc a5;
+-------+----------+------+-----+---------+-------+ |
Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+ |
id | int(11) | YES || NULL || | name | char(30) | YES || NULL || | id1 | int(11) | YES || NULL
|| +-------+----------+------+-----+---------+-------+
3 rows in set (0.00 sec)
MySQL [liangcb]> alter table a5 CHANGE id id int auto_increment;
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
// Error reporting can only have one auto increment column , And it must be defined as key
MySQL [liangcb]> alter table a5 CHANGE id id int auto_increment PRIMARY KEY ;
Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0
// There is no problem setting the primary key
MySQL [liangcb]> desc a5;
+-------+----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra
| +-------+----------+------+-----+---------+----------------+ |
id | int(11) | NO | PRI | NULL | auto_increment | | name | char(30) | YES || NULL
|| | id1 | int(11) | YES || NULL ||
+-------+----------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
// Add auto increment to non primary key
MySQL [liangcb]> ALTER TABLE a5
-> MODIFY COLUMN id int(11) NOT NULL FIRST ;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
MySQL [liangcb]> desc a5;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL ||
| name | char(30) | YES || NULL ||
| id1 | int(11) | YES || NULL ||
+-------+----------+------+-----+---------+-------+
3 rows in set (0.00 sec)
MySQL [liangcb]> alter table a5 CHANGE id1 id1 int auto_increment;
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
// Error reporting must be one key
MySQL [liangcb]> alter table a5 CHANGE id1 id1 int auto_increment Unique;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
MySQL [liangcb]> desc a5;
+-------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL ||
| name | char(30) | YES || NULL ||
| id1 | int(11) | NO | UNI | NULL | auto_increment |
+-------+----------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
summary :
1、 A table can only have one auto increment field ; If the primary key is already self incremented , Then this watch can no longer have self increment .
2、ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
Add auto increment field must be a key Whether it's Unique still PRIMARY KEY Fine .
边栏推荐
- Flink practical tutorial: advanced 4-window top n
- How to wrap QR code data
- MySQL de duplication query only keeps one latest record
- CMU博士论文 | 通过记忆的元强化学习,118页pdf
- Digital transformation solution for supply chain platform of mechanical equipment industry
- Tencent cloud database tdsql elite challenge Q & A (real-time update)
- Object declaration
- Minimize outlook startup + shutdown
- 北大、加州伯克利大学等联合| Domain-Adaptive Text Classification with Structured Knowledge from Unlabeled Data(基于未标记数据的结构化知识的领域自适应文本分类)
- How to solve the loss of video source during easynvr split screen switching?
猜你喜欢

Code implementation of CAD drawing online web measurement tool (measuring distance, area, angle, etc.)

Smart cockpit SOC competition upgraded, and domestic 7Nm chips ushered in an important breakthrough

Polar cycle graph and polar fan graph of high order histogram

Configuring error sets using MySQL for Ubuntu 20.04.4 LTS

Installation and use of Minio

Find my information | Apple may launch the second generation airtag. Try the Lenz technology find my solution

ACL2022 | MVR:面向开放域检索的多视角文档表征

University of North China, Berkeley University of California, etc. | Domain Adaptive Text Classification with structural Knowledge from unlabeled data

How to calculate individual income tax? You know what?

HDLBits-> Circuits-> Arithmetic Circuitd-> 3-bit binary adder
随机推荐
How to do API gateway routing? What are the other functions of API gateway?
How to deal with the situation of repeated streaming and chaotic live broadcast in easydss?
MySQL architecture SQL foundation 2
What is zero copy?
CMU doctoral thesis | meta reinforcement learning through memory, 118 Pages pdf
Basic concepts and common methods of syntactic dependency analysis
ACL2022 | MVR:面向开放域检索的多视角文档表征
Using h5ai to build Download Station
Find my information | Apple may launch the second generation airtag. Try the Lenz technology find my solution
Explain the rainbow ingress universal domain name resolution mechanism
Devops sharing: how to hold the meeting?
Code implementation of CAD drawing online web measurement tool (measuring distance, area, angle, etc.)
How to defend the security importance of API gateway
Bing 404? Microsoft suspended "search suggestions" in Bing mainland for 30 days
Detailed explanation of redisson distribution lock
北大、加州伯克利大學等聯合| Domain-Adaptive Text Classification with Structured Knowledge from Unlabeled Data(基於未標記數據的結構化知識的領域自適應文本分類)
Learn about reentrantlock
TMUX support, file transfer tool Trz / Tsz (trzsz) similar to RZ / SZ
TDD开发模式推荐流程
Leetcode algorithm interview sprint sorting algorithm theory (32)