~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to docs/rename.rst

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
Rename a table, or group of tables.
5
5
 
6
 
.. seealso::
7
 
   :doc:`/alter_table`
 
6
If you have an existing table old_name, you can create another table new_name; it will be empty but reptant he same structure, and then replace the existing table with the empty one as follows (assuming backup_table does not already exist):
 
7
 
 
8
.. code-block:: mysql
 
9
 
 
10
        CREATE TABLE new_name (...);
 
11
        RENAME TABLE old_name TO backup_table, new_name TO old_name;
 
12
 
 
13
When using a statement to rename more than one table, the order of operations are done from left to right. To swap two table names, use the following (assuming tmp_table does not already exist):
 
14
 
 
15
.. code-block:: mysql
 
16
 
 
17
        RENAME TABLE old_name TO tmp_table,
 
18
        new_name TO old_name,
 
19
        tmp_table TO new_name;
 
20
 
 
21
While RENAME is running, no other session can access any of the involved tables. 
 
22
 
 
23
.. seealso:: :doc:`/alter_table`