RENAME TABLE old_table TO tmp_table,
As long as two databases are on the same file system, you can use
from one database to another:
RENAME TABLE
Beginning with MySQL 5.0.2, if there are any triggers associated with a table which is moved to a
different database using
schema.
As of MySQL 5.0.14,
into a different database.
Any privileges granted specifically for the renamed table or view are not migrated to the new name.
They must be changed manually.
When you execute RENAME, you cannot have any locked tables or active transactions. You must
also have the
[577]
INSERT
If MySQL encounters any errors in a multiple-table rename, it does a reverse rename for all renamed
tables to return everything to its original state.
You cannot use
mysql>
ALTER TABLE orig_name RENAME new_name;
13.1.21.
TRUNCATE TABLE
TRUNCATE [TABLE]
TRUNCATE TABLE
deletes all rows, but there are practical differences under some circumstances.
For an
InnoDB
by one. As of MySQL 5.0.3, row by row deletion is used only if there are any
that reference the table. If there are no
by dropping the original table and creating an empty one with the same definition, which is much faster
than deleting rows one by one. (When fast truncation is used, it resets any
to zero. From MySQL 5.0.13 on, the
regardless of whether there is a foreign key constraint.)
In the case that
processes the constraints on each one. If the
rows from the child (referenced) table are deleted, and the truncated table becomes empty. If the
FOREIGN KEY
one by one and stops if it encounters a parent row that is referenced by the child, returning this error:
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign
key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1`
FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`))
This is the same as a
The count of rows affected by
statement.
For other storage engines,
• Truncate operations drop and re-create the table, which is much faster than deleting rows one by
one, particularly for large tables.
TRUNCATE TABLE
new_table TO old_table,
tmp_table TO new_table;
current_db.tbl_name
TO
TABLE, then the statement fails with the error
RENAME
RENAME TABLE
[576]
and
ALTER
DROP
privileges on the new table.
to rename a
RENAME
Syntax
tbl_name
empties a table completely. Logically, this is equivalent to a
table before version 5.0.3,
constraints reference the table,
FOREIGN KEY
constraint does not specify CASCADE, the
statement with no
DELETE
TRUNCATE TABLE
TRUNCATE TABLE
Syntax
other_db.tbl_name;
also works for views, as long as you do not try to rename a view
[577]
privileges on the original table, and the
table. However, you can use
TEMPORARY
processes
InnoDB
constraints,
FOREIGN KEY
counter is reset to zero by
AUTO_INCREMENT
FOREIGN KEY
TRUNCATE TABLE
clause.
WHERE
is accurate only when it is mapped to a
differs from
DELETE
1058
RENAME TABLE
Trigger in wrong
CREATE
ALTER TABLE
DELETE
by deleting rows one
TRUNCATE TABLE
FOREIGN KEY
performs fast truncation
InnoDB
AUTO_INCREMENT
TRUNCATE
deletes rows one by one and
InnoDB
constraint specifies
DELETE
statement deletes rows
in the following ways in MySQL 5.0:
to move a table
[576]
and
instead:
statement that
constraints
counter
TABLE,
CASCADE,
DELETE
Need help?
Do you have a question about the 5.0 and is the answer not in the manual?
Questions and answers