Skip to content

Latest commit

 

History

History
89 lines (67 loc) · 2.08 KB

sql-statement-rename-index.md

File metadata and controls

89 lines (67 loc) · 2.08 KB
title summary aliases
RENAME INDEX
TiDB 数据库中 RENAME INDEX 的使用概况。
/docs-cn/dev/sql-statements/sql-statement-rename-index/
/docs-cn/dev/reference/sql/statements/rename-index/

RENAME INDEX

ALTER TABLE .. RENAME INDEX 语句用于对已有索引进行重命名。这在 TiDB 中是即时操作的,仅需更改元数据。

语法图

AlterTableStmt
         ::= 'ALTER' 'IGNORE'? 'TABLE' TableName RenameIndexSpec ( ',' RenameIndexSpec )*

RenameIndexSpec
         ::= 'RENAME' ( 'KEY' | 'INDEX' ) Identifier 'TO' Identifier

示例

{{< copyable "sql" >}}

CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, c1 INT NOT NULL, INDEX col1 (c1));
Query OK, 0 rows affected (0.11 sec)

{{< copyable "sql" >}}

SHOW CREATE TABLE t1;
*************************** 1. row ***************************
       Table: t1
Create Table: CREATE TABLE `t1` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `c1` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `col1` (`c1`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
1 row in set (0.00 sec)

{{< copyable "sql" >}}

ALTER TABLE t1 RENAME INDEX col1 TO c1;
Query OK, 0 rows affected (0.09 sec)

{{< copyable "sql" >}}

SHOW CREATE TABLE t1;
*************************** 1. row ***************************
       Table: t1
Create Table: CREATE TABLE `t1` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `c1` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `c1` (`c1`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
1 row in set (0.00 sec)

MySQL 兼容性

RENAME INDEX 语句与 MySQL 完全兼容。如发现任何兼容性差异,请尝试 TiDB 支持资源

另请参阅