|
|
|
|
| |
The syntax for ALTER TABLE is as follows:
ALTER TABLE tbl_name action, ... ;
Each action specifies a modification you want to make to the table. Some database engines allow only a single action in an ALTER TABLE statement, but MySQL allows multiple actions; just separate the actions by commas. This extension to ALTER TABLE is useful because some types of table modifications cannot be performed with single-action statements. For example, it's impossible to change all the VARCHAR columns to CHAR columns by changing them one at a time. You must change them all at once.
The following examples show some of the capabilities of ALTER TABLE:
Renaming a table. Use a RENAME clause that specifies the new table name:
ALTER TABLE tbl_name RENAME TO new_tbl_name;
Another way to rename tables is with RENAME TABLE, available as of MySQL 3.23.23. The syntax looks like this:
RENAME TABLE old_name TO new_name;
One thing that RENAME TABLE can do that ALTER TABLE cannot is rename multiple tables in the same statement. For example, you can swap the names of two tables like this:
RENAME TABLE t1 TO tmp, t2 TO t1, tmp TO t1;
If you qualify a table name with a database name, you can move a table from one database to another by renaming it. Either of the following statements move the table t from the sampdb database to the test database:
ALTER TABLE sampdb.t RENAME TO test.t;
RENAME TABLE sampdb.t TO test.t;
You cannot rename a table to use a name that already exists, however.
|
|
|
|
|
|
| Link Partners: Asia florist, Flowers to India, Hong kong flowers, Site submit, Cheap web hosting, China florist, Japan florist |
|