Home > Database > Mysql Tutorial > body text

What is the mysql table creation statement?

王林
Release: 2020-12-01 09:48:37
Original
4456 people have browsed it

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.

What is the mysql table creation statement?

Syntax:

CREATE TABLE table_name (column_name column_type);
Copy after login

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

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!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template