Get the App
SLTechnology News&Howtos  ›  Database  › 

The method of creating New Table in MySQL Database

Shulou Source: shulou.com Published: 2022-05-31 22:53:45 09月28日 Update

This article will explain in detail the method of creating a new table in the MySQL database. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

CREATE TABLE syntax:

CREATE TABLE [IF NOT EXISTS] table_name (column_list) engine=table_type

[IF NOT EXISTS] is mainly used to determine whether the newly created table exists.

Engine needs to specify a storage engine. You can use any storage engine, 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 to specify a list of tables. The 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_name specifies 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 a null value.

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

AUTO_INCREMENT indicates that the value of the column automatically increases each time 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 / / Note that there cannot be "," will report an error) charset utf8 This is the end of this article on "how to create a new table in the MySQL database". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.

Tags: Data engine article storage database method creation more syntax good complex practical content only name size field indication article knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Tech Info Docker Huawei vpn