TINYTEXT [ BINARY ] [ CHARACTER SET charset_name ] [ COLLATE collation_name ]
TEXT [ BINARY ] [ CHARACTER SET charset_name ] [ COLLATE collation_name ]
MEDIUMTEXT [ BINARY ] [ CHARACTER SET charset_name ] [ COLLATE collation_name ]
LONGTEXT [ BINARY ] [ CHARACTER SET charset_name ] [ COLLATE collation_name ]
ENUM(value1, value2, ...) [ CHARACTER SET charset_name ] [ COLLATE collation_name ]
NULL or NOT NULL
Each column should be defined as NULL or NOT NULL. If this parameter is omitted, the database assumes NULL as the default.
DEFAULT default_value
Optional. It is the value to assign to the column if left blank or NULL.
AUTO_INCREMENT
Optional. It sets the column to be an autonumber field.
constraint_name
Optional. The name of the constraint if you define a primary key, unique constraint or foreign key.
index_col_name
Optional. It is the following syntax:
Note
There can only be one column in a table that is set as AUTO_INCREMENT and this column must be the primary key.
Example
Let's look at a MySQL CREATE TABLE example.
This MySQL CREATE TABLE example creates a table called contacts which has 4 columns and one primary key:
The first column is called contact_id which is created as an INT datatype (maximum 11 digits in length) and can not contain NULL values. It is set as an AUTO_INCREMENT field which means that it is an autonumber field (starting at 1, and incrementing by 1, unless otherwise specified.)
The second column is called last_name which is a VARCHAR datatype (maximum 30 characters in length) and can not contain NULL values.
The third column is called first_name which is a VARCHAR datatype (maximum 25 characters in length) and can contain NULL values.
The fourth column is called birthday which is a DATE datatype and can contain NULL values.
The primary key is called contacts_pk and is set to the contact_id column.
Next, let's create a table that has a DEFAULT VALUE.
This MySQL CREATE TABLE example creates a table called suppliers which has 3 columns and one primary key:
The first column is called supplier_id which is created as an INT datatype (maximum 11 digits in length) and can not contain NULL values. It is set as an AUTO_INCREMENT field.
The second column is called supplier_name which is a VARCHAR datatype (maximum 50 characters in length) and can not contain NULL values.
The third column is called account_rep which is a VARCHAR datatype (maximum 30 characters in length) and can not contain NULL values. If no value is provided for this column, the DEFAULT VALUE will be 'TBD'.
The primary key is called suppliers_pk and is set to the supplier_id column.