RENAME [TO] ;" to set and modify the name of the data table; TO is an optional parameter , whether it is used or not does not affect the results."/> RENAME [TO] ;" to set and modify the name of the data table; TO is an optional parameter , whether it is used or not does not affect the results.">

Home >Database >Mysql Tutorial >How to set table name in mysql?

How to set table name in mysql?

青灯夜游
青灯夜游Original
2020-09-27 17:51:193699browse

Mysql method to set the table name: use the alter table statement and use the SQL code "ALTER TABLE RENAME [TO] ;" to set and modify the data The name of the table; TO is an optional parameter, and whether it is used or not does not affect the results.

How to set table name in mysql?

Description of requirements:

Today I am migrating historical data of mysql tables and need to back up a certain table. , modify the name of the table, record the operation process here.

Operation process:

mysql> create table ts01 like ti_o_sms;       #创建表结构.这样的建表方式,不仅仅是表的结构,连带着索引也会同时创建.
Query OK, 0 rows affected (0.02 sec)

mysql> alter table ts01 rename to ts01_new;   #修改表名的语法:alter table rename to/as new_tablename;
Query OK, 0 rows affected (0.00 sec)

mysql> show tables;                      
+--------------------+
| Tables_in_mytest   |
+--------------------+
| sms_send_blacklist |
| td_b_sendobject    |
| ti_o_sms           |
| ts01_new           |
+--------------------+
4 rows in set (0.00 sec)或者
mysql> alter table ts01_new rename AS ts02;
Query OK, 0 rows affected (0.03 sec)

mysql> show tables;
+--------------------+
| Tables_in_mytest   |
+--------------------+
| sms_send_blacklist |
| td_b_sendobject    |
| ti_o_sms           |
| ts02               |
+--------------------+
4 rows in set (0.00 sec

Note: The table name has been successfully modified.

Official document syntax for modifying table name:

mysql help   RENAME

The above is the detailed content of How to set table name in mysql?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn