Home  >  Article  >  Database  >  How to create a data table in mysql?

How to create a data table in mysql?

藏色散人
藏色散人Original
2019-05-08 11:24:2826809browse

How to create a data table in mysql?

The following information is required to create a MySQL data table:

1.Table name

2.Table field name

3.Definition Each table field

Syntax

The following is the general SQL syntax for creating a MySQL data table:

CREATE TABLE table_name (column_name column_type);

In the following example we will use the RUNOOB database Create data table runoob_tbl:

CREATE TABLE IF NOT EXISTS `runoob_tbl`(
   `runoob_id` INT UNSIGNED AUTO_INCREMENT,
   `runoob_title` VARCHAR(100) NOT NULL,
   `runoob_author` VARCHAR(40) NOT NULL,
   `submission_date` DATE,
   PRIMARY KEY ( `runoob_id` )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

Example analysis:

● If you don’t want the field to be NULL, you can set the attribute of the field to NOT NULL. If you enter this when operating the database If the field data 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.

● The 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, CHARSET sets the encoding.

Related learning recommendations: mysql tutorial

The above is the detailed content of How to create a data table in mysql?. 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