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,...)".
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 数据类型, .... )
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:
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) )
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:
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!