Home > Database > Mysql Tutorial > How to create a new table in MySQL database

How to create a new table in MySQL database

autoload
Release: 2021-03-22 16:16:17
Original
3004 people have browsed it

CREATE TABLE syntax:

CREATE TABLE [IF NOT EXISTS] table_name(
        column_list
) engine=table_type;
Copy after login
  • [IF NOT EXISTS]Mainly used to determine whether the newly created table exists

  • #engineThe storage engine needs to be specified. Any storage engine can be used, such as: InnoDB, MyISAM, HEAP, EXAMPLE, CSV, ARCHIVE, MERGE, FEDERATED or NDBCLUSTER. If the storage engine is not explicitly declared, MySQL will use InnoDB by default.

  • column_list is more complex and is a list of specified tables. Columns of fields are separated by commas (,).

The syntax of column_list is as follows:

column_name data_type[size] [NOT NULL|NULL] [DEFAULT value] [AUTO_INCREMENT]
Copy after login
  • column_nameSpecify the name of the column . Each column has a specific data type and size , for example: varchar(50).

  • NOT NULL or NULL indicates whether the column accepts NULL values. The

  • DEFAULT value is used to specify the default value for the column.

  • AUTO_INCREMENTIndicates that the column's value is automatically incremented whenever a new row is inserted into the table. Each table has one and only one AUTO_INCREMENT column.

Example:

CREATE TABLE tasks (
    id INT NOT NULL,
    subject VARCHAR(45) NULL,
    start_date DATE NULL,
    end_date DATE NULL          //注意此处不能有"," 会报错
)charset utf8;
Copy after login

Recommendation:mysql tutorial

The above is the detailed content of How to create a new table in MySQL database. 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