Data tables in MySQL

Source: Internet
Author: User

Overview:

A data table (or table) is one of the most important components of a database and is the basis for other objects.

A relational database is a two-dimensional table

The line is called a record

Columns are called fields

Open database: use+ database name

View selected Databases select database ();

Create a data table

CREATE TABLE [if NOT EXISTS] table_name (column_name data_type,.. )

See if the data table exists, show TABLES [from db_name] [like ' pattern ' | WHERE Expr]

View all data tables in the MySQL database show TABLES from MySQL;

View data table structure: Show COLUMNS from Db_name;

INSERT

Inserting records

INSERT [into] tbl_name [(Col_name,..)] VALUES (Val,...);

Record lookup: SELECT expr,... From Tbl_name

NULL and NOT NULL NULL and non-empty

Guarantee the uniqueness of records: Auto_increment

Automatically numbered and must be combined with the primary key

By default, the starting value is 1, and each increment is 1

About PRIMARY key: PRIMARY key

PRIMARY KEY constraint

Only one primary key can exist per data table

The primary key guarantees the uniqueness of the record

Primary key is not NULL automatically

The primary key allows assignment, but the same value cannot be assigned.

Note: The auto_increment must be used with the primary key primary key, but the primary key primary key can not be used with auto_increment.

Unique constraint

UNIQUE KEY

Unique constraint

Unique constraints guarantee the uniqueness of records

A field of a unique constraint can be controlled (NULL)

Multiple unique constraints can exist for each data table

Primary KEY constraints a single data table can have more than one unique constraint, but there are some differences when creating an index.

Default constraint

Default value

Automatically assigns a default value when you insert a record without explicitly assigning a value to the field

Data type: Character, integer, float, date-time

Data table operations: Inserting records, finding records

Record actions: Creating a data table, using constraints

Data tables in MySQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.