Error 1068: Multiple primary key defined.
Error 1075: Incorrect table definition; there can be only one auto column and it must be defined as a key.
CREATE TABLE statement, you may encounter the following error:Error 4109: Failed to generate invisible primary key. Auto-increment column already exists.
show create table. Please use the following method to view the GIPK.
show create table.mysql> show create table tb1;+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| tb1 | CREATE TABLE `tb1` (`my_row_id` bigint unsigned NOT NULL AUTO_INCREMENT /*!80023 INVISIBLE */,`id` int DEFAULT NULL,`c` varchar(16) DEFAULT NULL,PRIMARY KEY (`my_row_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.01 sec)
mysql> select @@sql_generate_invisible_primary_key;+--------------------------------------+| @@sql_generate_invisible_primary_key |+--------------------------------------+| 1 |+--------------------------------------+1 row in set (0.00 sec)
alter table table_name add primary key(id);
Error 1068: Multiple primary key defined.mysql> show create table tb1;+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| tb1 | CREATE TABLE `tb1` (`my_row_id` bigint unsigned NOT NULL AUTO_INCREMENT /*!80023 INVISIBLE */,`id` int DEFAULT NULL,`c` varchar(16) DEFAULT NULL,PRIMARY KEY (`my_row_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.01 sec)
alter table tb1 drop column my_row_id, add primary key(id);
mysql> show create table tb1;+-------+--------------------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-------+--------------------------------------------------------------------------------------------------------------------------------------+| tb1 | CREATE TABLE `tb1` (`id` int NOT NULL,`c` varchar(16) DEFAULT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |+-------+--------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)
alter table table_nameadd column new_id bigint primary key;
Error 1068: Multiple primary key defined.mysql> show create table tb2;+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| tb2 | CREATE TABLE `tb2` (`my_row_id` bigint unsigned NOT NULL AUTO_INCREMENT /*!80023 INVISIBLE */,`i` int DEFAULT NULL,`c` varchar(16) DEFAULT NULL,PRIMARY KEY (`my_row_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
alter table table_namedrop column my_row_id,add column new_id bigint primary key;
mysql> show create table tb2;+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| tb2 | CREATE TABLE `tb2` (`i` int DEFAULT NULL,`c` varchar(16) DEFAULT NULL,`new_id` bigint unsigned NOT NULL AUTO_INCREMENT,PRIMARY KEY (`new_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
alter table table_nameadd column new_id bigint unsigned not null auto_increment key;
Error 1075: Incorrect table definition; there can be only one auto column and it must be defined as a key.mysql> show create table tb3;+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| tb3 | CREATE TABLE `tb3` (`my_row_id` bigint unsigned NOT NULL AUTO_INCREMENT /*!80023 INVISIBLE */,`i` int DEFAULT NULL,`c` varchar(16) DEFAULT NULL,PRIMARY KEY (`my_row_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
alter table table_namedrop column my_row_id,add column new_id bigint unsigned not null auto_increment key;
mysql> show create table tb3;+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| tb3 | CREATE TABLE `tb3` (`i` int DEFAULT NULL,`c` varchar(16) DEFAULT NULL,`new_id` bigint unsigned NOT NULL AUTO_INCREMENT,PRIMARY KEY (`new_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
create table table_name (id bigint unsigned NOT NULL AUTO_INCREMENT UNIQUE KEY,c varchar(16));
Error 4109: Failed to generate invisible primary key. Auto-increment column already exists.create table table_name (id bigint unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,c varchar(16));
mysql> show create table tb4;+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| tb4 | CREATE TABLE `tb4` (`id` bigint unsigned NOT NULL AUTO_INCREMENT,`c` varchar(16) DEFAULT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
CREATE TABLE tb5 (f1 INT, f2 DATE) PARTITION BY KEY(f2) PARTITIONS 2;
Error 1235: This version of MySQL doesn't yet support 'generating invisible primary key for the partitioned tables.Apakah halaman ini membantu?
Anda juga dapat Menghubungi Penjualan atau Mengirimkan Tiket untuk meminta bantuan.
masukan