Invalid ale Data Processing and constraints, and invalid ale Data Processing
Other DML statements for data processing: Constraints
Constraint is a provision
** NOT NULL
UNIQUE
PRIMARY KEY
FOREIGN KEY
CHECK **
You can create constraints when creating tables.
After creating a table, you can modify the constraints.
You can define constraints at the table or column level.
You can view constraints through data dictionary
Table-level constraints and column-level constraints:
UNIQUE:
Unique constraint. Multiple NULL values are allowed: NULL.
Foreign key:
Foreign key: indicates the column in the child table at the table level.
REFERENCES: columns marked in the parent table
On delete cascade: When the columns in the parent table are deleted, the corresponding columns in the child table are also deleted.
On delete set null (cascade NULL): The corresponding columns in the subtable are empty.
CHECK:
It can be understood as a custom constraint.
Constraint addition and Deletion
Query Constraints
In practice, I will write an article separately. The most difficult part of learning SQL is subquery, which requires more practice. Here I will tell you the Highly Efficient contact method, that is, pay attention to the writing format. For example:
-- Query the information of the Department with the lowest average salary and the average salary of the department SELECT d. *, (SELECT avg (salary) FROM employees WHERE department_id = d. department_id) FROM orders dWHERE department_id = (SELECT department_id FROM employees group by department_id HAVING avg (salary) = (SELECT min (avg (salary) FROM employees group by department_id ))
This writing format facilitates analysis