Home  >  Article  >  Database  >  What is the table creation statement in mysql

What is the table creation statement in mysql

王林
王林Original
2020-09-01 14:24:1336424browse

The table creation statement in mysql is [CREATE TABLE table_name (column_name column_type);]. For example, you can create a new "phpcn_tb" table through the syntax [CREATE TABLE `phpcn_tb`].

What is the table creation statement in mysql

Common SQL syntax for creating MySQL data tables:

CREATE TABLE table_name (column_name column_type);

(Recommended tutorial: mysql tutorial)

Example:

CREATE TABLE `phpcn_tb`(
   `phpcn_id` INT UNSIGNED AUTO_INCREMENT,
   `phpcn_title` VARCHAR(100) NOT NULL,
   `phpcn_author` VARCHAR(40) NOT NULL,
   `submission_date` DATE,
   PRIMARY KEY ( `phpcn_id` )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

Explanation:

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 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.

(Learning video recommendation: mysql video tutorial)

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 Set up the storage engine.

CHARSET Set encoding.

The above is the detailed content of What is the table creation statement in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn