Home >Database >Mysql Tutorial >What is the command to create a database table in mysql?

What is the command to create a database table in mysql?

下次还敢
下次还敢Original
2024-04-22 18:45:33749browse

In MySQL, use the CREATE TABLE table_name (column_name data_type [column_constraint], ...) command to create a database table, which contains the table name, column name, data type, and optional column constraints.

What is the command to create a database table in mysql?

MySQL command to create a database table

In MySQL, the command to create a database table is:

<code class="sql">CREATE TABLE table_name (
  column_name1 data_type [column_constraint],
  column_name2 data_type [column_constraint],
  ...
);</code>

Parameter description

  • table_name: The name of the table to be created.
  • column_nameN: The column name in the table.
  • data_type: The data type of the column. Can be CHAR, VARCHAR, INT, FLOAT, DATETIME, etc.
  • column_constraint: Optional parameter, used to set constraints on the column, such as NOT NULL, PRIMARY KEY, etc.

Example

Create a table named users containing id, name and email Three columns:

<code class="sql">CREATE TABLE users (
  id INT NOT NULL AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  email VARCHAR(255) UNIQUE
);</code>

Description: The

  • id column is an integer, non-empty and automatically incremented.
  • name column is a variable length string, up to 255 characters, non-empty. The
  • email column is a variable-length string, up to 255 characters, that is unique.

The above is the detailed content of What is the command to create a database table in mysql?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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