要在MySQL中重命名表,以下是语法-
rename table yourOldTableName to yourNewTableName ;
让我们首先创建一个表-
mysql> create table DemoTable1 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserName varchar(100), UserAge int, UserCountryName varchar(100) );
让我们检查表的描述-
mysql> desc DemoTable1;
这将产生以下输出-
+-----------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+---------+----------------+ | Id | int(11) | NO | PRI | NULL | auto_increment | | UserName | varchar(100) | YES | | NULL | | | UserAge | int(11) | YES | | NULL | | | UserCountryName | varchar(100) | YES | | NULL | | +-----------------+--------------+------+-----+---------+----------------+ 4 rows in set (0.20 sec)
现在,我们将使用RENAME命令在MySQL中重命名表-
mysql> rename table DemoTable1 to DemoTable2;
让我们再次检查表的描述-
mysql> desc DemoTable2;
这将产生以下输出-
+-----------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+---------+----------------+ | Id | int(11) | NO | PRI | NULL | auto_increment | | UserName | varchar(100) | YES | | NULL | | | UserAge | int(11) | YES | | NULL | | | UserCountryName | varchar(100) | YES | | NULL | | +-----------------+--------------+------+-----+---------+----------------+ 4 rows in set (0.00 sec)