Home >Database >Mysql Tutorial >How to write the complete process of creating a table in MySQL
The steps to create a MySQL table are as follows: Open the MySQL command line client and select the database. Write a CREATE TABLE statement and specify the table name, column name, data type, primary key and other information. Execute the CREATE TABLE statement to create the table. Use the SHOW TABLES statement to verify that the table has been created.
How to create a MySQL table
Creating a MySQL table involves the following steps:
1. Open the MySQL command line client
Type mysql -u username -p password
in the command line.
2. Select the database
Use the USE database name
command to select the database where you want to create the table.
3. Write the CREATE TABLE
statement
CREATE TABLE
statement is used to create a table. The syntax is as follows:
<code>CREATE TABLE 表名 ( 列名1 数据类型 NOT NULL, 列名2 数据类型 NOT NULL, 列名3 数据类型 NOT NULL, ... 列名N 数据类型 NOT NULL, PRIMARY KEY (主键列) );</code>
INT
, VARCHAR
, DATE
). NULL
. 4. Execute the statement
Use ;
to end the CREATE TABLE
statement, and then press Enter to execute it.
Example:
To create a table named customers
, which contains id
, name
and email
columns, you can write the following statement:
<code>CREATE TABLE customers ( id INT NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, PRIMARY KEY (id) );</code>
5. To verify whether the table has been created
you can use SHOW TABLES
Statement to verify that the table has been created:
<code>SHOW TABLES;</code>
It will display a list of all tables in the database, including the table you just created.
The above is the detailed content of How to write the complete process of creating a table in MySQL. For more information, please follow other related articles on the PHP Chinese website!