TableConstraint in sqlparser::ast::table_constraints - Rust

Enum TableConstraint 

Source

pub enum TableConstraint {
    Unique(UniqueConstraint),
    PrimaryKey(PrimaryKeyConstraint),
    ForeignKey(ForeignKeyConstraint),
    Check(CheckConstraint),
    Index(IndexConstraint),
    FulltextOrSpatial(FullTextOrSpatialConstraint),
}
Expand description

A table-level constraint, specified in a CREATE TABLE or an ALTER TABLE ADD <constraint> statement.

§

MySQL definition for UNIQUE constraints statements:\

  • [CONSTRAINT [<name>]] UNIQUE <index_type_display> [<index_name>] [index_type] (<columns>) <index_options>

where:

§

MySQL definition for PRIMARY KEY constraints statements:\

  • [CONSTRAINT [<name>]] PRIMARY KEY [index_name] [index_type] (<columns>) <index_options>

Actually the specification have no [index_name] but the next query will complete successfully:

CREATE TABLE unspec_table (
  xid INT NOT NULL,
  CONSTRAINT p_name PRIMARY KEY index_name USING BTREE (xid)
);

where:

  • index_type is USING {BTREE | HASH}
  • index_options is {index_type | COMMENT 'string' | ... %currently unsupported stmts% } ...
§

A referential integrity constraint ([ CONSTRAINT <name> ] FOREIGN KEY (<columns>) REFERENCES <foreign_table> (<referred_columns>) { [ON DELETE <referential_action>] [ON UPDATE <referential_action>] | [ON UPDATE <referential_action>] [ON DELETE <referential_action>] }).

§

[ CONSTRAINT <name> ] CHECK (<expr>) [[NOT] ENFORCED]

§

MySQLs index definition for index creation. Not present on ANSI so, for now, the usage is restricted to MySQL, as no other dialects that support this syntax were found.

{INDEX | KEY} [index_name] [index_type] (key_part,...) [index_option]...

§

MySQLs fulltext definition. Since the SPATIAL definition is exactly the same, and MySQL displays both the same way, it is part of this definition as well.

Supported syntax:

{FULLTEXT | SPATIAL} [INDEX | KEY] [index_name] (key_part,...)

key_part: col_name

§
§
§
§
§
§