In MySQL, you can use the CREATE TABLE statement to create a data table, specifying the table name, column name, data type and constraints. Specific steps include: 1. Connect to the MySQL database; 2. Use the CREATE TABLE statement to create a data table.
MySQL Create Data Table Command
In MySQL, you can use theCREATE TABLE
statement to create a data table. The syntax of this statement is as follows:
CREATE TABLE table_name ( column_name1 data_type [constraints], column_name2 data_type [constraints], ... );
Parameter description:
INT
,VARCHAR
,DECIMAL
, etc.NOT NULL
,UNIQUE
,PRIMARY KEY
, etc.Example:
The following statement creates a data table namedusers
, which containsid
,name
andemail
Columns:
CREATE TABLE users ( id INT NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, email VARCHAR(255) UNIQUE );
Description:
Constraint Indicates that the column cannot be a
NULLvalue.
The constraint indicates that the
idcolumn will automatically generate a unique value.
The constraint means that the values in the
emailcolumn must be unique.
Detailed field type:
Description | |
---|---|
INTEGER | |
Variable length string | |
Decimal with decimal places | |
Date | |
Time | |
Date and time | |
Boolean value ( | TRUEor FALSE) |
Description | |
---|---|
NULL |
| UNIQUE
PRIMARY KEY | |
FOREIGN KEY | |
Connect to the MySQL database.
Specify table name, column name, data type and constraints.
The above is the detailed content of How to create data table command in mysql. For more information, please follow other related articles on the PHP Chinese website!