Login To InderWeb ! Just Play !

Username:
Password:

UserSubmittedComments

rename table in mysql or sql command statement syntax and example

The RENAME TABLE statement defines a new name for an existing table in the database enviornment
Scope/Usage

Application Programs

SQL Syntax

RENAME TABLE [Owner.] TableName TO NewTableName

Parameters

[Owner.]TableName

Denotes the old table that is to be renamed.You can enclose database owner name in prefix.

NewTableName

    is the new table name.

Description

    *    All indexes, columns, default columns, constraints, referential authorization, rules, and user authorities tables dependent on a renamed table will be renamed.
    *   RENAME statement is not allowed for IMAGE/SQL tables.
    *  When using RENAME command, data and grants made for tables are carried forward for the new name. No unload, load data, or recreating index is necessary.
    *  All views dependent on a renamed table will be dropped.
    * If a table has check constraints, then that table cannot be renamed.

Authorization

You must have authorized for running this command.You can own this table or you must have proper privileges set for tale.
Example

   RENAME TABLE dbname.user to users;

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 use RENAME TABLE to move a table from one database to another:

RENAME TABLE current_db.tbl_name TO other_db.tbl_name;

See detail for mysql at :- http://dev.mysql.com/doc/refman/5.0/en/rename-table.html