What is the table creation statement in mysql

王林
Release: 2020-09-05 11:34:44
Original
36356 people have browsed it

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);
Copy after login

(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;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!