DQL statements on

1 relational database

  • - between the table and the table, the relationship can be established; called primary foreign key;

  • Primary key: uniquely identifies a record, can not be repeated, is not allowed to empty, is used to ensure data integrity
    1: int type, self-energizing
    2: varchar type, the UUID
    . 3: Custom (current time stamp + + Encoding + int increment sequence); for distributed systems

  • Foreign key: another table is the primary key, foreign key can be repeated, it can be a null value, and to establish contact with the other tables. So, if it comes to a foreign key, it must be to involve at least two tables.

  • Using the foreign key needs to satisfy the following conditions:

  1. Two tables must be InnoDB tables are, and they are not temporary tables.

Note: InnoDB database engine is. There are two common MySQL engine: InnoDB and MyISAM, which does not support foreign keys.

  1. Establishing a corresponding relationship between foreign key columns must have similar InnoDB internal data types.

  2. Establish a foreign key relationship must be established in the corresponding column of the index.

  3. If the explicitly given CONSTRAINT symbol, that symbol must be unique within the database. If not explicitly given, InnoDB will automatically be created.
    Here Insert Picture Description
    Here Insert Picture DescriptionFor example:
    books and table books category table / student and class table / table departments and employees / users and borrow books and relationship

The relationship between 2 tables

2.1 one (one corresponding to the ID card)

1: A table primary key, foreign key table B;
2: a field of Table A, Table B is a foreign key, the cut is provided a unique index;
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

2.2-to-many (a plurality of books corresponding to books category)

1: a field of Table A, Table B is a foreign key;
Here Insert Picture Description

2.3-many (teacher and class)

1: General described many to many relationship between two tables by a third party table
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

Published 31 original articles · won praise 36 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_46288317/article/details/105079246