DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

(mysql.info.gz) RENAME TABLE

Info Catalog (mysql.info.gz) DROP VIEW (mysql.info.gz) Data Definition
 
 13.2.12 `RENAME TABLE' Syntax
 -----------------------------
 
      RENAME TABLE TBL_NAME TO NEW_TBL_NAME
          [, TBL_NAME2 TO NEW_TBL_NAME2] ...
 
 This statement renames one or more tables.  It was added in MySQL
 3.23.23.
 
 The rename operation is done atomically, which means that no other
 thread can access any of the tables while the rename is running. For
 example, if you have an existing table `old_table', you can create
 another table `new_table' that has the same structure but is empty, and
 then replace the existing table with the empty one as follows:
 
      CREATE TABLE NEW_TABLE (...);
      RENAME TABLE OLD_TABLE TO BACKUP_TABLE, NEW_TABLE TO OLD_TABLE;
 
 If the statement renames more than one table, renaming operations are
 done from left to right. If you want to swap two table names, you can
 do so like this (assuming that no table named `tmp_table' currently
 exists):
 
      RENAME TABLE OLD_TABLE TO TMP_TABLE,
                   NEW_TABLE TO OLD_TABLE,
                   TMP_TABLE TO NEW_TABLE;
 
 As long as two databases are on the same filesystem you can also rename
 a table to move it from one database to another:
 
      RENAME TABLE CURRENT_DB.TBL_NAME TO OTHER_DB.TBL_NAME;
 
 When you execute `RENAME', you can't have any locked tables or active
 transactions.  You must also have the `ALTER' and `DROP' privileges on
 the original table, and the `CREATE' and `INSERT' privileges on the new
 table.
 
 If MySQL encounters any errors in a multiple-table rename, it will do a
 reverse rename for all renamed tables to get everything back to the
 original state.
 
Info Catalog (mysql.info.gz) DROP VIEW (mysql.info.gz) Data Definition
automatically generated byinfo2html