Oracle 5.0 Reference Manual page 1061

Table of Contents

Advertisement

example, if the table contains
selected values are assigned to the
columns is assigned its default value, either that specified explicitly in the column definition or the
implicit column data type default if the definition contains no default. If the
many columns
• If strict SQL mode is enabled and any of these initial columns do not have an explicit default value,
the statement fails with an error.
The following example illustrates
mysql>
CREATE TABLE t1 (i1 INT DEFAULT 0, i2 INT, i3 INT, i4 INT);
Query OK, 0 rows affected (0.05 sec)
mysql>
CREATE TABLE IF NOT EXISTS t1 (c1 CHAR(10)) SELECT 1, 2;
Query OK, 1 row affected, 1 warning (0.01 sec)
Records: 1
mysql>
SELECT * FROM t1;
+------+------+------+------+
| i1
| i2
+------+------+------+------+
|
0 | NULL |
+------+------+------+------+
1 row in set (0.00 sec)
To ensure that the binary log can be used to re-create the original tables, MySQL does not permit
concurrent inserts during
13.1.10.2. Using
FOREIGN KEY
MySQL supports foreign keys, which let you cross-reference related data across tables, and
key
constraints, which help keep this spread-out data consistent. The essential syntax for a foreign key
constraint definition in a
[CONSTRAINT [symbol]] FOREIGN KEY
[index_name] (index_col_name, ...)
REFERENCES
[ON DELETE reference_option]
[ON UPDATE reference_option]
reference_option:
RESTRICT | CASCADE | SET NULL | NO ACTION
index_name
defined explicitly. Otherwise, if MySQL creates an index for the foreign key, it uses
the index name.
Foreign keys definitions are subject to the following conditions:
• Foreign key relationships involve a
with identical values pointing back to its parent. The
table. The parent and child tables must use the same storage engine. They must not be
tables.
• Corresponding columns in the foreign key and the referenced key must have similar data types. The
size and sign of integer types must be the same. The length of string types need not be the same.
For nonbinary (character) string columns, the character set and collation must be the same.
• MySQL requires indexes on foreign keys and referenced keys so that foreign key checks can be
fast and not require a table scan. In the referencing table, there must be an index where the foreign
key columns are listed as the first columns in the same order. Such an index is created on the
referencing table automatically if it does not exist. This index might be silently dropped later, if you
create another index that can be used to enforce the foreign key constraint. index_name, if given, is
used as described previously.
CREATE TABLE
columns and the
n
(m
> n), an error occurs.
IF NOT EXISTS
Duplicates: 0
Warnings: 0
| i3
| i4
|
1 |
2 |
CREATE TABLE ...
Constraints
CREATE TABLE
tbl_name
(index_col_name,...)
represents a foreign key ID. If given, this is ignored if an index for the foreign key is
Syntax
produces
SELECT
rightmost columns in the table. Each of the initial
m
handling:
SELECT.
or
statement looks like this:
ALTER TABLE
parent table
that holds the central data values, and a
FOREIGN KEY
1041
columns, where
< n, the
m
m
n
part produces too
SELECT
foreign
index_name
child table
clause is specified in the child
TEMPORARY
m
for

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents