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

How to create a new table in MySQL database

autoload
autoloadOriginal
2021-03-22 16:16:172977browse

CREATE TABLE syntax:

CREATE TABLE [IF NOT EXISTS] table_name(
        column_list
) engine=table_type;
  • [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]
  • 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;

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!

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