语法格式
RENAME TABLE [database_name.]old_table_name TO [database_name.]
new_table_name;
参数说明
database_name:是要修改表隶属的数据库名称,可选项;省略此参数,即为
USE 后的数据库名称。
old_table_name:是表的原有名称。
new_table_name:是表的要修改后的新名称。
功能
RENAME TABLE 的功能就是将一张已经存在的表的名称修改为一个不存在的新的
表名称。
示例
示例1:更改表tx1 的名称为tx_1。
GBase UP 产品手册 5 数据库管理指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 650
gbase>
SELECT
table_schema,table_name,table_rows
FROM
information_schema.tables
WHERE
table_schema='test' AND table_name = 'tx1';
+--------------+------------+------------+
| table_schema | table_name | table_rows |
+--------------+------------+------------+
| test | tx1 | 0 |
+--------------+------------+------------+
1 row in set
gbase> USE test;
Query OK, 0 rows affected
gbase> RENAME TABLE test.tx1 to test.tx_1;
Query OK, 0 rows affected
gbase>
SELECT
table_schema,table_name,table_rows
FROM
information_schema.tables
WHERE
table_schema='test' AND table_name = 'tx_1';
+--------------+------------+------------+
| table_schema | table_name | table_rows |
+--------------+------------+------------+
| test | tx_1 | 0 |
+--------------+------------+------------+
1 row in set