Get the App
SLTechnology News&Howtos  ›  Database  › 

What is the syntax to build a table in mysql

Shulou Source: shulou.com Published: 2022-06-01 04:11:28 09月20日 Update

The purpose of this article is to share with you about what the syntax for creating tables is in mysql. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.

The table-building statement in mysql is: [CREATE TABLE table_name (column_name column_type);]. For example, we want to create a new phpcn_tb table with the following syntax: [CREATE TABLE `phpcn_ tb`].

General SQL syntax for creating MySQL data tables:

CREATE TABLE table_name (column_name column_type)

For 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

Description:

If you do not want the field to be NULL, you can set the property of the field to NOT NULL. If you enter the data of the field as NULL when operating the database, you will report an error.

The AUTO_INCREMENT definition is listed as a self-increasing attribute, which is generally used for primary keys, and the value is automatically incremented by 1.

The PRIMARY KEY keyword is used to define the column primary key. You can use multiple columns to define the primary key, separated by commas.

ENGINE sets up the storage engine.

CHARSET sets the encoding.

Thank you for reading! So much for sharing the syntax of table building in mysql. I hope the above content can be helpful to you so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.

Tags: Syntax fields data real content attributes more good practical keywords engines values databases datasheets articles see knowledge articles coding Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MariaDB vpn Xiaomi Shulou Tech Info