H I O X INDIA
MySQL Tutorial
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Templates 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)
Español Français 中文 Deutsch
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

Mysql Tutorial
Introduction
How to Install
Database
Datatypes
Tables
INSERT
SELECT
UPDATE
DELETE
Operators
Functions
Ask Your Doubts
More about Mysql
Feedback




Renaming Mysql Database Table


Topic

How to rename a Mysql database table?



Explanation

Renaming tables :

    The RENAME statement is used to rename one or more tables in a database.
The syntax is
RENAME TABLE tbl_name TO new_tbl_name
    [, tbl_name2 TO new_tbl_name2] ...
    The following example query renames the student table as class table.

mysql> rename table student to class;
Query OK, 0 rows affected (0.00 sec)


    Now we can view the table whether the name is changed by the following query.

mysql> show tables;
+--------------------+
| Tables_in_sample   |
+--------------------+
| class              |
+--------------------+
1 row in set (0.00 sec)
    If the query renames more than one table, renaming operations are done from left to right.

    We can also swap two table names. Let us assume tmp table which does not exists.

Example :
RENAME TABLE emp1 TO tmp,
             emp2 TO emp1,
             tmp TO emp2;
    We can also use RENAME TABLE to move a table from one database to another.

Example :

RENAME TABLE current_db.tbl_name TO other_db.tbl_name;






        MySQL is the most popular open source Relational database Management system (RDBMS). Being a open source anyone can use and change the software for their needs. Hope you enjoy this tutorial. We welcome your Valuable feedbacks or suggestions on this MySQL tutorial. This is a copyright content.


privacy policy     license     sitemap
© 2004-2009 HIOX INDIA - hioxindia.com

Other Links