CREATE TABLE

Define a new table

Synopsis

CREATE TABLE statement

Diagram(
  Stack(
    Sequence(
      "CREATE",
      "TABLE",
      Optional(Sequence("IF", "NOT", "EXISTS"), "skip"),
      Sequence(Link("table-name"))
    ),
    Choice(
      0,
      Sequence(
        OneOrMore(Link("field-definition"), ","),
        Optional(
          Sequence(",", OneOrMore(Link("table-constraint"), ",")),
          "skip"
        )
      ),
      Sequence(OneOrMore(Link("table-constraint"), ","))
    )
  )
);

Parameters

IF NOT EXISTS

Do not throw an error if a table with the same name already exists.

table-name

The name of the table to be created.

Field definition

Diagram(
  Link("field-path", "/docs/essentials/expressions/#field-path"),
  OptionalSequence(
    Link("type-name", "/docs/essentials/data-types"),
    OneOrMore(Link("field-constraint"))
  )
);
table-name

The name of the table to be created.

Field constraint

Diagram(
  Choice(
    0,
    Sequence("PRIMARY", "KEY"),
    Sequence("UNIQUE"),
    Sequence("NOT", "NULL"),
    Sequence(
      "DEFAULT",
      Choice(
        0,
        Sequence("(", Link("expr", "/docs/essentials/expressions"), ")"),
        Sequence(Link("expr", "/docs/essentials/expressions"))
      )
    ),
    Sequence("CHECK", "(", Link("expr", "/docs/essentials/expressions"), ")")
  )
);

Table constraint

Diagram(
  Choice(
    0,
    Sequence(
      "PRIMARY",
      "KEY",
      "(",
      Link("field-path", "/docs/essentials/expressions/#field-path"),
      ")"
    ),
    Sequence(
      "UNIQUE",
      "KEY",
      "(",
      Link("field-path", "/docs/essentials/expressions/#field-path"),
      ")"
    ),
    Sequence("CHECK", "(", Link("expr", "/docs/essentials/expressions"), ")")
  )
);

Last modified November 9, 2021: Add CHECK (10b7e10)