Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: alter table books add primary key时不能指定CLUSTERED
Test environment, newly installed.
Server version: 5.7.25-TiDB-v6.1.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible
mysql> show create table books\G
*************************** 1. row ***************************
Table: books
Create Table: CREATE TABLE `books` (
`id` bigint(20) NOT NULL,
`title` varchar(100) DEFAULT NULL,
`type` enum('Magazine','Novel','Life','Arts','Comics','Education & Reference','Humanities & Social Sciences','Science & Technology','Kids','Sports') DEFAULT NULL,
`published_at` datetime DEFAULT NULL,
`stock` int(11) DEFAULT NULL,
`price` decimal(15,2) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
# Syntax error
mysql> alter table books add primary key(id) CLUSTERED;
ERROR 8200 (HY000): Adding clustered primary key is not supported. Please consider adding NONCLUSTERED primary key instead
# Dropping and recreating the table with primary key specified as CLUSTERED works fine
mysql> drop table books;
Query OK, 0 rows affected (0.21 sec)
mysql> CREATE TABLE `books` (
-> `id` bigint NOT NULL,
-> `title` varchar(100) DEFAULT NULL,
-> `type` enum('Magazine','Novel','Life','Arts','Comics','Education & Reference','Humanities & Social Sciences','Science & Technology','Kids','Sports') DEFAULT NULL,
-> `published_at` datetime DEFAULT NULL,
-> `stock` int DEFAULT NULL,
-> `price` decimal(15,2) DEFAULT NULL,
-> primary key(id) CLUSTERED
-> );
Query OK, 0 rows affected (0.08 sec)
mysql> show create table books\G
*************************** 1. row ***************************
Table: books
Create Table: CREATE TABLE `books` (
`id` bigint(20) NOT NULL,
`title` varchar(100) DEFAULT NULL,
`type` enum('Magazine','Novel','Life','Arts','Comics','Education & Reference','Humanities & Social Sciences','Science & Technology','Kids','Sports') DEFAULT NULL,
`published_at` datetime DEFAULT NULL,
`stock` int(11) DEFAULT NULL,
`price` decimal(15,2) DEFAULT NULL,
PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin