Go to the first, previous, next, last section, table of contents.


CREATE TABLE syntax.

CREATE TABLE table_name ( create_definition,... )

create_definition:
  column_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT]
                   [ PRIMARY KEY ] [reference_definition]
  or	PRIMARY KEY ( index_column_name,... )
  or	KEY [index_name] KEY( index_column_name,...)
  or	INDEX [index_name] ( index_column_name,...)
  or	UNIQUE [index_name] ( index_column_name,...)
  or    FOREIGN KEY index_name ( index_column_name,...) [reference_definition]
  or	CHECK (expr)

type:
        TINYINT[(length)] [UNSIGNED] [ZEROFILL]
  or    SMALLINT[(length)] [UNSIGNED] [ZEROFILL]
  or    MEDIUMINT[(length)] [UNSIGNED] [ZEROFILL]
  or    INT[(length)] [UNSIGNED] [ZEROFILL]
  or    INTEGER[(length)] [UNSIGNED] [ZEROFILL]
  or    BIGINT[(length)] [UNSIGNED] [ZEROFILL]
  or    REAL[(length,decimals)] [UNSIGNED] [ZEROFILL]
  or    DOUBLE[(length,decimals)] [UNSIGNED] [ZEROFILL]
  or	FLOAT[(length,decimals)] [UNSIGNED] [ZEROFILL]
  or	DECIMAL[(length,decimals)] [UNSIGNED] [ZEROFILL]
  or	NUMERIC[(length,decimals)] [UNSIGNED] [ZEROFILL]
  or    CHAR(length) [BINARY],
  or    VARCHAR(length) [BINARY],
  or    DATE
  or    TIME
  or    TIMESTAMP
  or    DATETIME
  or    TINYBLOB
  or    BLOB
  or    MEDIUMBLOB
  or    LONGBLOB
  or    TINYTEXT
  or    TEXT
  or    MEDIUMTEXT
  or    ENUM(value1,value2,value3...)
  or    SET(value1,value2,value3...)

index_column_name:
        column_name [ (length) ]

reference_definition:
        REFERENCES table_name [( index_column_name,...)]
                   [ MATCH FULL | MATCH PARTIAL]
                   [ ON DELETE reference_option]
                   [ ON UPDATE reference_option]

reference_option:
        RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT

See section Column types.

The FOREIGN KEY, CHECK and REFERENCE syntax are only for compatibility. (To make it easier to port code from other SQL servers and run applications that create tables with references). They don't actually do anything. See section What functionality is missing in MySQL.

If a column doesn't have a DEFAULT value and is not declared as NOT NULL, the default value is NULL.

If a column doesn't have a DEFAULT value and is declared as NOT NULL, MySQL will automaticly assign a default value for the field.


Go to the first, previous, next, last section, table of contents.