Home  >  Article  >  Database  >  What is the command to create a table structure in mysql?

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

下次还敢
下次还敢Original
2024-04-22 19:54:521077browse

In MySQL, the command to create a table structure is CREATE TABLE, and its syntax is: CREATE TABLE table_name (column_name1 data_type1 [constraints], ...);, where table_name is the table name and column_name is the column name. data_type is the column data type and constraints are optional column constraints.

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

MySQL command to create a table structure

In MySQL, the command to create a table structure is CREATE TABLE. The syntax format is as follows:

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

where:

  • table_name is the name of the table to be created.
  • column_name is the column name in the table.
  • data_type is the data type of the column, such as INT, VARCHAR, DATE, etc.
  • constraints are optional column constraints, such as NOT NULL, PRIMARY KEY, etc.

Example

Create a table named customers with the following columns:

  • id: Integer primary key
  • name: Variable length string type, the maximum length is 255
  • email: Yes Variable-length string type, allowed to be NULL

using the following CREATE TABLE command:

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

The above is the detailed content of What is the command to create a table structure 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