MySQL Learning--Data sheet basic Operation 1

Source: Internet
Author: User

Select Database

Create a data table

Include field name and data type two parts

View Data Sheet

Using PRIMARY KEY constraints

The primary key is also called the main code, can be a unique representation of a record in the table, divided into single Chini and multi-field joint primary key

Single Field primary key

There are two ways to define a primary key:

1. Specify the primary key at the end

2. Identify after the primary key line

Multi-field Federated primary key

No ID, combine two fields to master key

using FOREIGN KEY constraints

Foreign keys are used to establish a connection between data in two tables, which can be one or more columns. A table can have one or more foreign keys.

The foreign key is first a field in its table, which may not be the primary key for the table, but the primary key for the other table

For example, the primary key for a departmental table is ID, and there is a key in the employee table that is related to this ID

Example: Defining a data table TB_EMP5 and creating a FOREIGN key constraint on a table

Define the data table TB_EMP5 let its key deptid be associated with the TB_DEPT1 's primary key ID as a foreign key.

Association refers to the relation between related tables in a relational database. He is represented by the same attribute or group of attributes. The foreign key of the child table must be associated with the primary key of the parent table, and the data type of the associated field must match.

Using non-null constraints

Field name The field type is not null,

Indicates that its insertion value cannot be null

Using Uniqueness constraints

Requires the column to be unique, allowed to be empty, but only one null value appears

Using Default Constraints

Specify the default value for a column

View the data table structure

Describe

Desc Table name

Show CREATE TABLE

Setting the property value of a table automatically increases

For example, let the ID automatically increase by 1

For example, execute an INSERT statement and query

Modify the data table name

MySQL Learning--Data sheet basic Operation 1

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.