How to create data table command in mysql

下次还敢
Release: 2024-04-14 18:15:51
Original
1154 people have browsed it

In MySQL, you can use the CREATE TABLE statement to create a data table, specifying the table name, column name, data type and constraints. Specific steps include: 1. Connect to the MySQL database; 2. Use the CREATE TABLE statement to create a data table.

How to create data table command in mysql

MySQL Create Data Table Command

In MySQL, you can use theCREATE TABLEstatement to create a data table. The syntax of this statement is as follows:

CREATE TABLE table_name ( column_name1 data_type [constraints], column_name2 data_type [constraints], ... );
Copy after login

Parameter description:

  • table_name:Data table name.
  • column_name:Data table column name.
  • data_type:Data type, such asINT,VARCHAR,DECIMAL, etc.
  • constraints:Column constraints, such asNOT NULL,UNIQUE,PRIMARY KEY, etc.

Example:

The following statement creates a data table namedusers, which containsid,nameandemailColumns:

CREATE TABLE users ( id INT NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, email VARCHAR(255) UNIQUE );
Copy after login

Description:

  • ##NOT NULLConstraint Indicates that the column cannot be aNULLvalue.
  • AUTO_INCREMENTThe constraint indicates that theidcolumn will automatically generate a unique value.
  • UNIQUEThe constraint means that the values in theemailcolumn must be unique.

Detailed field type:

Data type Description INT INTEGER VARCHAR(length) Variable length string DECIMAL(length, decimal places) Decimal with decimal places DATE Date TIME Time DATETIME Date and time BOOLEAN Boolean value (
TRUEorFALSE)
##Constraint type:

Constraint Type ##NOT NULL Column cannot be UNIQUE The value in the column must be unique PRIMARY KEY The value in the column uniquely identifies the row FOREIGN KEY Foreign key, which relates this table to another table Steps to create a data table:
Description
NULL

Connect to the MySQL database.

    Use the
  1. CREATE TABLE
  2. statement to create a data table.
  3. Specify table name, column name, data type and constraints.

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

Related labels:
source:php.cn
Statement of this 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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!