Mysql basis.

When SQL server before learning the simple learned a little of the underlying SQL, Mysql will start from the foreign key constraint to continue to learn directly.

Foreign key constraint: foreign key

Let table and table generation relations, so as to ensure the correctness of the data.

1, add foreign key when you create the table:

  create table  ...(

    ......

    Foreign key column,

    the name of the foreign key constraint foreign key (foreign key column name) references a main table (the primary table column names)

  )

2, delete the foreign key:

  alter table ... drop foreign key foreign key name.

3, add foreign key:

 alter table ... add constraint name of the foreign key foreign key (foreign key column name) references a main table (the primary table column names)

Cascade operation:

1, add a cascade operation:

  Syntax: alter table add constraint foreign key table name foreign key (foreign key column name) references the master table (primary table column names) on update cascade on delete cascade cascading updates and deletes

Multi-table relationship:

1, many: establishing a foreign key in a multi-party, pointing to a primary key.

2-many: it needs third intermediate sheet, the intermediate sheet contains at least two fields of the table as a foreign key intermediate, the primary key of the table two

3, one: either add {} foreign key unique primary key pointing to the other.

Paradigm:

1, a first paradigm (1NF): each column is indivisible atomic data item.

2, a second paradigm (2NF): on the basis of 1NF, non-code must be entirely dependent on the property code (to eliminate non-primary property 1NF main part of the function on the basis of the code dependent.

  Several concepts: * functional dependency: A -> B, if the value of the A attribute (group), to determine the value of the unique properties of B, called B depends on A.

          For example: Student ID -> Name. (Student number, course name) -> Score

       * Fully functional dependency: A -> B, determines if A is a group attribute, the attribute value B need to rely on all attribute values ​​A set of attributes.

          For example :( student number, course name) -> Score

       * Part functional dependency: A -> B, determines if A is a group attribute, the attribute value of B depends on only some of the attribute values ​​of A can be set.

          For example :( student number, course name) -> name.

       * Dependent transfer function: A -> B, B -> C, if the A attribute (set) value, to determine the value of the unique properties of B, then the value of B by attribute, attribute value C may be determined, dependent transfer function called C and A.

          For example: Student ID -> department name, department name -> Head

       * Code: if in a table, an attribute or group, are totally dependent on all other attributes, which codes called attribute (attribute group) for the table.

       * Main attributes: Attribute Code * group, all non-primary property attribute, the attribute code out property.

The third paradigm (3NF): on the basis of the 2NF, any non-primary property is not dependent on other non-primary property (2NF eliminate the dependency on the basis of transfer.

Multi-table query:

Multi-table query is generated Cartesian product, there will be useless data, elimination of useless data

1, the inner link query.

  1, the implicit link: Select a column name from the table, Table II where the primary key related conditions

  2, the explicit link: Select from the table column names join a condition related to the primary key on Table II

2, outer join query.

  1, left outer: Select from the table column names Table II left join on a condition related to the primary key

    Query is left of all data tables and their intersection part.

  2, right outer connection: Select from the table column names Table II on a right join condition relating to the primary key

    Query is the right table all the data and its intersection portion.

3, sub-queries.

Query nested queries.

Different situations subquery:

  1, a separate single line: the condition that is determined by the operator. 

  2, single multi-line: As a condition,: in

  3, multiple rows and columns: as a virtual table, on the column.

Transaction:

1, the basic description of the transaction:

  *: Business operations if a multi-step, the transaction management, these operations either at the same time succeed or fail at the same time. (Joe Smith transfers to John Doe ....)

  *:: 1, open transaction: start transaction

         2, Rollback: rollback

         3, submitted to: commit

  *: The way the transaction submitted: 1, automatic submission: mysql is the automatic submission, automatic submit a DML statement once the transaction

            2, manual submission: you need to open a transaction, and then submitted.

  *: Default modify transactions submission: 1, view the transaction submission SELECT @@ autocommit; 1- automatically submitted

                2, Review: set @@ autocommit = 0;

2, the four characteristics of the transaction:

  * Atom: the smallest unit can not be separated, either while the success or failure at the same time.

  * Persistence: When a transaction is committed or rolled back, the database persistent data.

  * Isolation: between multiple transactions, independent of each other.

  * Consistency: transactions before and after the operation, the same amount of data.

3, transaction isolation level.

Guess you like

Origin www.cnblogs.com/zhangyuhao/p/10923628.html