Database Reference
In-Depth Information
CHAPTER 4
Table Management
4.0. Introduction
This chapter covers topics that relate to creating and populating tables:
• Cloning a table
•
Copying from one table to another
• Using temporary tables
• Generating unique table names
• Determining what storage engine a table uses or converting it from one storage
engine to another
Many of the examples in this chapter use a table named
mail
containing rows that track
mail message traffic between users on a set of hosts (see
Recipe 3.0
). To create and load
this table, change location into the
tables
directory of the
recipes
distribution and run
this command:
%
mysql cookbook < mail.sql
4.1. Cloning a Table
Problem
You want to create a table that has exactly the same structure as an existing table.
Solution
Use
CREATE
TABLE
…
LIKE
to clone the table structure. To also copy some or all of the
rows from the original table to the new one, use
INSERT
INTO
…
SELECT
.