In the database, you can use the "CREATE TABLE" statement to create a table. The syntax format is "CREATE TABLE table name (column name 1 data type (maximum length) 1 [,...] column name n data type ( Maximum length)n);".
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
Creation of tables in database
The process of creating a data table is the process of specifying the attributes of the data columns, and it is also the process of implementing data integrity (including entity integrity, reference integrity and domain integrity) constraints.
Basic syntax
In MySQL, you can use the CREATE TABLE statement to create a table. The syntax format is:
CREATE TABLE <表名> ([表定义选项]);
Copy after login
Among them, the format of [table definition option] is:
<列名1> <数据类型(size)1> [,…] <列名n> <数据类型(size)n>
Copy after login
The main syntax and usage instructions of the CREATE TABLE statement are as follows:
CREATE TABLE: For creating a table with a given name, you must have table CREATE permissions.
: Specifies the name of the table to be created, given after CREATE TABLE, and must comply with the identifier naming rules. The table name is specified as db_name.tbl_name to create the table in a specific database. It can be created this way regardless of whether there is a current database. db-name can be omitted when creating a table in the current database. If you use quoted distinguished names, the database and table names should be quoted separately. For example, 'mydb'.'mytbl' is legal, but 'mydb.mytbl' is not.
: Table creation definition, consisting of column name (col_name), column definition (column_definition), and possible null value specifications, integrity constraints, or table indexes composition.
size: Specifies the maximum length of columns in the table.
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.
Tip: When using CREATE TABLE to create a table, you must specify the following information:
The name of the table to be created is not case-sensitive, and keys in the SQL language cannot be used. words, such as DROP, ALTER, INSERT, etc.
The name and data type of each column (field) in the data table. If you create multiple columns, separate them with commas.
The above is the detailed content of How to create a database table. For more information, please follow other related articles on the PHP Chinese website!
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn