How to implement constraints in SQL
Editor to share with you how to achieve SQL constraints, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
1. Five types
Non-empty not null unique unique primary key primary foreign key foreign check check
Description:
The foreign key on delete cascade/set null option is specified when the foreign key is defined
2. View
User_constraints
User_cons_colums
3. Create
Column level: constraint emp_id primary key is set along with the column
Table level: constraint con_pk primary key (emp_id) set after all column definitions are complete
4. Delete
Alter table emp drop constraint
Delete not null: alter table emp02 modify deptno null
Cascade options:
Alter table dept02 drop constraint pk_dept02_deptno cascade
When you delete a primary key constraint on a parent table, the cascade deletes the foreign key constraint of the child table first.
5. Add
Alter table emp add constraint
Add not null: alter table emp02 modify empno not null
6. Invalidation takes effect
Alter table.. Disable constraint...
Alter table.. Enable constraint...
The above is all the content of the article "how to achieve constraints in SQL". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!