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 the CREATE TABLE
statement to create a data table. The syntax of this statement is as follows:
<code>CREATE TABLE table_name ( column_name1 data_type [constraints], column_name2 data_type [constraints], ... );</code>
Parameter description:
INT
, VARCHAR
, DECIMAL
, etc. NOT NULL
, UNIQUE
, PRIMARY KEY
, etc. Example:
The following statement creates a data table named users
, which contains id
, name
and email
Columns:
<code>CREATE TABLE users ( id INT NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, email VARCHAR(255) UNIQUE );</code>
Description:
Constraint Indicates that the column cannot be a
NULL value.
The constraint indicates that the
id column will automatically generate a unique value.
The constraint means that the values in the
email column must be unique.
Detailed field type:
Description | |
---|---|
INTEGER | |
Variable length string | |
Decimal with decimal places | |
Date | |
Time | |
Date and time | |
Boolean value ( | TRUE or 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!