Home > Database > Mysql Tutorial > How to create a data table in mysql database

How to create a data table in mysql database

王林
Release: 2023-01-03 09:23:51
Original
4092 people have browsed it

Mysql method of creating a data table: Use the general SQL syntax [CREATE TABLE table_name (column_name column_type);] to create it successfully.

How to create a data table in mysql database

#The operating environment of this article: windows10 system, mysql 5.7, thinkpad t480 computer.

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

CREATE TABLE table_name (column_name column_type);
Copy after login

In the following example we will create a data table tbl in the RUNOOB database:

CREATE TABLE IF NOT EXISTS `tbl`(
   `id` INT UNSIGNED AUTO_INCREMENT,
   `title` VARCHAR(100) NOT NULL,
   `author` VARCHAR(40) NOT NULL,
   `submission_date` DATE,
   PRIMARY KEY ( `id` ))ENGINE=InnoDB DEFAULT CHARSET=utf8;
Copy after login

Analysis:

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

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 and CHARSET sets the encoding.

Learning recommendation: mysql tutorial

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