Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement constraints in SQL

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report