Home >Database >Mysql Tutorial >How to create a table using sql statement in mysql
To create a table in MySQL using SQL, you can use the CREATE TABLE statement. The syntax is: CREATE TABLE table_name (column_name data_type [NOT NULL] [DEFAULT default_value], ...). Among them, table_name is the name of the table, column_name is the name of the column, data_type is the data type of the column, NOT NULL specifies that the column cannot be empty, and DEFAULT default_value specifies the default value of the column. For example, to create a table named cu
How to create a table using SQL statements in MySQL
1. Basic syntax for creating a table
<code class="sql">CREATE TABLE table_name ( column_name data_type [NOT NULL] [DEFAULT default_value], ... );</code>
2. Example
Suppose you want to create a table named "customers" containing the following columns:
You can use the following SQL statement to create the table:
<code class="sql">CREATE TABLE customers ( id INT NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, email VARCHAR(255) DEFAULT '', phone_number VARCHAR(255) );</code>
3. Other notes Note
ALTER TABLE
statement to add, delete, or modify columns. The above is the detailed content of How to create a table using sql statement in mysql. For more information, please follow other related articles on the PHP Chinese website!