The table creation statement in mysql is [CREATE TABLE table_name (column_name column_type);]. column_name represents the field name, column_type represents the field type.
Syntax:
CREATE TABLE table_name (column_name column_type);
(Recommended tutorial: mysql tutorial)
Example:
We will create the data table run_tbl in the RUN database:
CREATE TABLE IF NOT EXISTS `run_tbl`( `run_id` INT UNSIGNED AUTO_INCREMENT, `run_title` VARCHAR(100) NOT NULL, `run_author` VARCHAR(40) NOT NULL, `submission_date` DATE, PRIMARY KEY ( `run_id` ))ENGINE=InnoDB DEFAULT CHARSET=utf8;
Instructions:
If you don’t want the field to be NULL, you can set the attribute of the field to NOT NULL. When operating the database, if If the data entered in this field is NULL, an error will be reported.
AUTO_INCREMENT is defined as an auto-incrementing attribute, generally used for primary keys, and the value will automatically increase by 1.
PRIMARY KEY keyword is used to define the column as the primary key. You can define a primary key using multiple columns, separated by commas.
ENGINE sets the storage engine and CHARSET sets the encoding.
The above is the detailed content of What is the mysql table creation statement?. For more information, please follow other related articles on the PHP Chinese website!