Oracle 5.0 Reference Manual page 1060

Table of Contents

Advertisement

mysql>
SELECT * FROM foo;
+---+
| n |
+---+
| 1 |
+---+
mysql>
CREATE TABLE bar (m INT) SELECT n FROM foo;
Query OK, 1 row affected (0.02 sec)
Records: 1
Duplicates: 0
mysql>
SELECT * FROM bar;
+------+---+
| m
| n |
+------+---+
| NULL | 1 |
+------+---+
1 row in set (0.00 sec)
For each row in table foo, a row is inserted in
new columns.
In a table resulting from
part come first. Columns named in both parts or only in the
of
columns can be overridden by also specifying the column in the
SELECT
If any errors occur while copying the data to the table, it is automatically dropped and not created.
You can precede the
SELECT
unique key values. With IGNORE, new rows that duplicate an existing row on a unique key value are
discarded. With REPLACE, new rows replace rows that have the same unique key value. If neither
nor
IGNORE
REPLACE
CREATE TABLE ... SELECT
intentionally to make the statement as flexible as possible. If you want to have indexes in the created
table, you should specify these before the
mysql>
CREATE TABLE bar (UNIQUE (n)) SELECT n FROM foo;
Some conversion of data types might occur. For example, the
preserved, and
VARCHAR
NULL) and, for those columns that have them,
clause.
DEFAULT
When creating a table with
expressions in the query. If you do not, the
names.
CREATE TABLE artists_and_works
SELECT artist.name, COUNT(work.artist_id) AS number_of_works
FROM artist LEFT JOIN work ON artist.id = work.artist_id
GROUP BY artist.id;
You can also explicitly specify the data type for a generated column:
CREATE TABLE foo (a TINYINT NOT NULL) SELECT b+1 AS a FROM bar;
For
CREATE TABLE ...
exists, MySQL handles the statement as follows:
• The table definition given in the
definition does not match that of the existing table. MySQL attempts to insert the rows from the
part anyway.
SELECT
• If there is a mismatch between the number of columns in the table and the number of columns
produced by the
SELECT
CREATE TABLE
Warnings: 0
CREATE TABLE ...
by
or
IGNORE
REPLACE
is specified, duplicate unique key values result in an error.
does not automatically create any indexes for you. This is done
SELECT
columns can become
CREATE TABLE ...
CREATE
SELECT, if
IF NOT EXISTS
CREATE TABLE
part, the selected values are assigned to the rightmost columns. For
1040
Syntax
with the values from
bar
SELECT, columns named only in the
part come after that. The data type
SELECT
to indicate how to handle rows that duplicate
statement:
AUTO_INCREMENT
columns. Retrained attributes are
CHAR
SET, COLLATION, COMMENT, and the
CHARACTER
SELECT, make sure to alias any function calls or
statement might fail or result in undesirable column
is given and the destination table already
part is ignored. No error occurs, even if the
and default values for the
foo
CREATE TABLE
part.
CREATE TABLE
attribute is not
(or
NULL
NOT

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents