Home > Database > Mysql Tutorial > How to add a table in mysql

How to add a table in mysql

WBOY
Release: 2022-01-18 15:29:44
Original
5927 people have browsed it

In mysql, you can use the "CREATE TABLE" statement to add a table. The function of this statement is to create a table in the database. You can also use this statement to specify the data type that the column can accommodate. The syntax is "CREATE TABLE table Name (column name 1 data type, column name 2 data type,...)".

How to add a table in mysql

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

How to add a table in mysql

CREATE TABLE statement

The CREATE TABLE statement is used to create a table in the database.

SQL CREATE TABLE syntax

CREATE TABLE 表名称
(
列名称1 数据类型,
列名称2 数据类型,
列名称3 数据类型,
....
)
Copy after login

The data type (data_type) specifies what data type the column can accommodate. The following table contains the most commonly used data types in SQL:

How to add a table in mysql

The example is as follows:

How to create a table named "Person".

The table contains 5 columns, the column names are: "Id_P", "LastName", "FirstName", "Address" and "City":

CREATE TABLE Persons
(
Id_P int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)
Copy after login

Data type of the Id_P column is an int, containing integers. The data type of the remaining 4 columns is varchar, with a maximum length of 255 characters.

The empty "Persons" table looks like this:

How to add a table in mysql

Recommended learning: mysql video tutorial

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