Oracle 5.0 Reference Manual page 1059

Table of Contents

Advertisement

Cloning or Copying a Table
You can create one table from another by adding a
statement:
TABLE
CREATE TABLE
For more information, see
Use
to create an empty table based on the definition of another table, including any column
LIKE
attributes and indexes defined in the original table:
CREATE TABLE
The copy is created using the same version of the table storage format as the original table. The
[578]
SELECT
works only for base tables, not for views.
LIKE
CREATE TABLE ... LIKE
options that were specified for the original table, or any foreign key definitions.
If the original table is a
To create a
In MySQL 5.0, changes to the SQL mode do not affect
mode is different from the mode in effect when the original table was created, the statement succeeds
even if the table definition is invalid for the new mode.
13.1.10.1.
CREATE TABLE ... SELECT
You can create one table from another by adding a
statement:
TABLE
CREATE TABLE
MySQL creates new columns for all elements in the SELECT. For example:
mysql>
CREATE TABLE test (a INT NOT NULL AUTO_INCREMENT,
->
->
This creates a
statement, and should not be used following the SELECT; this would result in a syntax error.
TABLE
The same is true for other
Notice that the columns from the
overlapped onto it. Take the following example:
CREATE TABLE
Important
The original
CREATE TABLE
options are stored by MySQL when the table is created. The information is
retained so that if you change storage engines, collations or other settings using
an
ALTER TABLE
This enables you to change between
though the row formats supported by the two engines are different.
Because the text of the original statement is retained, but due to the way
that certain values and options may be silently reconfigured (such as the
ROW_FORMAT), the active table definition (accessible through
STATUS) and the table creation string (accessible through
SHOW TABLE
TABLE) will report different values.
CREATE
new_tbl
SELECT * FROM orig_tbl;
Section 13.1.10.1,
new_tbl
LIKE orig_tbl;
privilege is required on the original table.
does not preserve any
TEMPORARY
destination table, use
TEMPORARY
new_tbl
SELECT * FROM orig_tbl;
PRIMARY KEY (a), KEY(b))
ENGINE=MyISAM SELECT b,c FROM test2;
table with three columns, a, b, and c. The
MyISAM
CREATE TABLE
SELECT
Syntax
statement, including all specifications and table
statement, the original table options specified are retained.
InnoDB
SELECT
"CREATE TABLE ... SELECT
DATA DIRECTORY
table,
CREATE TABLE ... LIKE
CREATE TEMPORARY TABLE ...
CREATE TABLE ...
Syntax
SELECT
options such as CHARSET.
statement are appended to the right side of the table, not
1039
and
table types even
MyISAM
DESCRIBE
statement at the end of the
Syntax".
or
INDEX DIRECTORY
does not preserve TEMPORARY.
LIKE. If the current SQL
statement at the end of the
option is part of the
ENGINE
or with
SHOW
CREATE
table
LIKE.
CREATE
CREATE

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents