The statement to create a table in the sql statement is "CREATE TABLE", and the specific syntax format is "CREATE TABLE table name ([table definition option])[table option][partition option];"; where, "[ Table definition option]" is in the format of "column name 1 type 1 [,…] column name n type n".
The operating environment of this tutorial: Dell G3 computer, Windows 7 system, MySQL version 5.5.19.
In MySQL, you can use theCREATE TABLE
statement to create a table.
The syntax format is:
CREATE TABLE 表名 ([表定义选项])[表选项][分区选项];
Among them, the format of[Table definition option]
is:
列名1 类型1 [,…] 列名n 类型n
CREATE TABLE statement The main syntax and usage instructions are as follows:
CREATE TABLE: used to create a table with a given name, you must have table CREATE permissions.
722e3d59fd24604761db25f00f9b264f: Specifies the name of the table to be created, given after CREATE TABLE, and must comply with the identifier naming rules.
f52e9980a8ff3ab048a5a8e987465670: Table creation definition, consisting of column name (col_name), column definition (column_definition), and possible null value specifications, integrity constraints, or table indexes composition.
By default, the table is created in the current database. If the table already exists, there is no current database, or the database does not exist, an error will occur.
Recommended tutorial:mysql video tutorial
Example:Select the database test_db to create the table and create the tb_emp1 data table
mysql> USE test_db; Database changed mysql> CREATE TABLE tb_emp1 -> ( -> id INT(11), -> name VARCHAR(25), -> deptId INT(11), -> salary FLOAT -> ); Query OK, 0 rows affected (0.37 sec)
Check whether the data table is created successfully:
mysql> SHOW TABLES; +--------------------+ | Tables_in_test_db | +--------------------+ | tb_emp1 | +--------------------+ 1 rows in set (0.00 sec)
For more programming-related knowledge, please visit:Programming Learning Website! !
The above is the detailed content of What is the statement to create a table in sql statement. For more information, please follow other related articles on the PHP Chinese website!