foreign key constraints
After adding a foreign key to the child table, records cannot be deleted or updated in the main table because there is a foreign key association.
Delete the foreign key. Pay attention to the name of the foreign key when we added it.
After using the cascade operation, you can operate the main table data, and the foreign keys of the sub-table will also change accordingly.
If set null, after deleting the primary key information corresponding to the main table, the foreign key information corresponding to the sub-table becomes empty.
Multiple table relationship
Create intermediate table
Can display visual interface
Eliminate invalid Cartesian product conditions and output the foreign key in the subtable equal to the primary key in the main table
Create aliases to simplify operations,
But if an alias is used, the original table name cannot be used in subsequent conditions, and the alias can only be used.
inner can be omitted
outer can be omitted
Right outer join is only different from left outer join left -> right
Similarly, these two connections can be converted into each other
Tables must be aliased in self-join queries
Left outer join query in self-join, query all contents of the left table
The things queried must be the same, the field types and the number of columns must be the same.
Union all directly merges the two query contents without deduplication.
Unio alone deduplicates the query content and outputs it.
Note that brackets must be added to the subsequent subquery.
Even if the subsequent subquery is the same table as the previous one, there is no need to add an alias, which is different from the previous self-join query.
The variables in the following brackets are separate, and the variables default to the ones in the table after "from" in the brackets.
The output meets the conditions in in, as long as it meets one of them.
The output must satisfy all conditions in all
any can be replaced by some and the effect will be the same
As long as one is established
The conditions behind where can be written as
(Variable 1, Variable 2) = (select Variable 1, Variable 2 from .... )
Multiple reception
Query related to multiple tables
Code can be formatted