MySQL table rename

MySQL table rename

How to rename a table through SQL code and how to move a table between two databases.

You can rename any table using the rename sql command.
Please note that previously present data will NOT be lost

Sintax

RENAME TABLE [old_database.]old_table TO [new_database.]new_table;


As described, the origin and destination database name are optional; they should be included only when you want to move the table between two databases. If you would just rename the table, and thus wouldn't need to move in another database, the command will be:

RENAME TABLE old_table TO new_table;

Example
If you want to move the "customers" table to another database, here's the code:

RENAME TABLE project.customers TO project2.customers2;

If you only want to rename the same table from "customers" to "customers2" instead here is the solution:

RENAME TABLE customers TO customers2;

Publication details

Category: MySQL

Published by: loryzz on date: 06.03.2008 23:20:15

Last edit by: loryzz on date: 02.04.2008 16:54:26

Statistics

Details  This article has been viewed 850 times.

Send to

add to digg add to reddit add to furl add to facebook add to delicious add to google add to stumbleupon add to technorati add to ask add to live

Ratings

  • Currently 0; ?>/ TOTALSTARS
  • 1
  • 2
  • 3
  • 4
  • 5

Comments

Details 0 user comments, 0 still waiting.

Leave a comment

All comments must be approved by site administrator.
Please write comments on topic. Spam will be never approved.


Confirmation code

Please take a look to image and insert character into the form field.