~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to docs/create_table.rst

  • Committer: Olaf van der Spek
  • Date: 2011-03-29 12:04:36 UTC
  • mto: (2257.1.1 build) (2276.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2258.
  • Revision ID: olafvdspek@gmail.com-20110329120436-vozkuer8vqgh027p
Always call assert()

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
CREATE TABLE
2
2
============
3
3
 
4
 
A CREATE statement in SQL creates an object inside of Drizzle. One of the most common CREATE command is the CREATE TABLE command.
5
 
 
6
 
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] table_name
7
 
    (create_definition, ...)
8
 
    [engine_options]
9
 
 
10
 
    or:
11
 
 
12
 
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] table_name
13
 
    [(create_definition, ...)]
14
 
    [engine_options]
15
 
    select_statement
16
 
 
17
 
    or:
18
 
 
19
 
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] table_name
20
 
    LIKE different_table_name
21
 
    [engine_options]
22
 
 
23
 
create_definition:
 
4
A CREATE statement in SQL creates an object inside of Drizzle. One of
 
5
the most common CREATE commands is the CREATE TABLE command.
 
6
 
 
7
.. code-block:: mysql
 
8
 
 
9
    CREATE [TEMPORARY] TABLE [IF NOT EXISTS] table_name
 
10
      (create_definition, ...)
 
11
      [engine_options]
 
12
 
 
13
or:
 
14
 
 
15
.. code-block:: mysql
 
16
 
 
17
    CREATE [TEMPORARY] TABLE [IF NOT EXISTS] table_name
 
18
      [(create_definition, ...)]
 
19
      [engine_options]
 
20
      select_statement
 
21
 
 
22
or:
 
23
 
 
24
.. code-block:: mysql
 
25
 
 
26
    CREATE [TEMPORARY] TABLE [IF NOT EXISTS] table_name
 
27
      LIKE different_table_name
 
28
      [engine_options]
 
29
 
 
30
create_definition
 
31
-----------------
 
32
 
 
33
::
 
34
 
24
35
    column_name column_definition
25
 
  | [CONSTRAINT [symbol] ] PRIMARY KEY [index_type]
26
 
    (index_column_name, ...)
27
 
  | INDEX [index_name] (index_column_name, ...)
28
 
    (index_column_name, ...)
29
 
  | [CONSTRAINT [symbol] ] UNIQUE [INDEX]
30
 
    (index_column_name, ...)
31
 
  | [CONSTRAINT [symbol] ] FOREIGN KEY [index_name] (index_column_name, ...)
 
36
    [CONSTRAINT [symbol] ] PRIMARY KEY [index_type]
 
37
    (index_column_name, ...)
 
38
    INDEX [index_name] (index_column_name, ...)
 
39
    (index_column_name, ...)
 
40
    [CONSTRAINT [symbol] ] UNIQUE [INDEX]
 
41
    (index_column_name, ...)
 
42
    [CONSTRAINT [symbol] ] FOREIGN KEY [index_name] (index_column_name, ...)
32
43
    reference_definition
33
 
  | CHECK (expr)
34
 
 
35
 
column_definition:
36
 
  data_type [NOT NULL | NULL] [DEFAULT default_value]
 
44
    CHECK (expr)
 
45
 
 
46
column_definition
 
47
-----------------
 
48
 
 
49
::
 
50
 
 
51
        data_type [NOT NULL | NULL] [DEFAULT default_value]
37
52
    [AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY]
38
53
    [COMMENT 'string']
39
54
    [reference_definition]
40
55
 
41
 
data_type:
42
 
  | INTEGER
43
 
  | BIGINT
44
 
  | DOUBLE[(length, decimals)]
45
 
  | DECIMAL[(length[,decimals])]
46
 
  | DATE
47
 
  | TIMESTAMP
48
 
  | DATETIME
49
 
  | VARCHAR(length) [COLLATE collation_name]
50
 
  | VARBINARY(length)
51
 
  | BLOB
52
 
  | TEXT [BINARY] [COLLATE collation_name]
53
 
  | ENUM(value1, value2, value3, ...) [COLLATE collation_name]
54
 
 
55
 
reference_option:
 
56
data_type
 
57
---------
 
58
 
 
59
        * INTEGER
 
60
        * BIGINT
 
61
        * DOUBLE[(length, decimals)]
 
62
        * DECIMAL[(length[,decimals])]
 
63
        * DATE
 
64
        * TIMESTAMP
 
65
        * DATETIME
 
66
        * VARCHAR(length) [COLLATE collation_name]
 
67
        * VARBINARY(length)
 
68
        * BLOB
 
69
        * TEXT [BINARY] [COLLATE collation_name]
 
70
        * ENUM(value1, value2, value3, ...) [COLLATE collation_name]
 
71
 
 
72
reference_option
 
73
----------------
 
74
 
56
75
  RESTRICT | CASCADE | SET NULL | NO ACTION
57
76
 
58
 
engine_options:
 
77
engine_options
 
78
---------------
 
79
 
59
80
    engine_option [[,] engine_option] ...
60
81
 
61
 
engine_option:
 
82
engine_option
 
83
-------------
 
84
 
62
85
  ENGINE = engine_name
63
86
  { engine_specific }