这篇文章主要介绍数据库中约束的validate和able怎么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
创建唯一性约束,自动创建了和约束名一样的唯一性索引
创建check约束,不会产生索引
创建外键约束,不会产生索引
启用约束:
enable( validate) :启用约束,创建索引,对已有及新加入的数据执行约束.
enable novalidate :启用约束,创建索引,仅对新加入的数据强制执行约束,而不管表中的现有数据.
禁用约束:
disable( novalidate):关闭约束,删除索引,可以对约束列的数据进行修改等操作.
disable validate :关闭约束,删除索引,不能对表进行 插入/更新/删除等操作.
enable\validate用到的地方
1、物化视图要实现查询重写时,则必须保证相关联表的主外键约束的状态为enable、validate
2、要实现星型转换时,必须保证fact表即主表字段的外键约束的状态为enable、validate
SQL> alter table SALES disable novalidate constraint SALES_CHANNEL_FK;
Table altered.
SQL> select constraint_name,constraint_type,status,validated from user_constraints where table_name='SALES' and constraint_type='R' and CONSTRAINT_NAME='SALES_CHANNEL_FK';
CONSTRAINT_NAME CONSTRAINT_TYPE STATUS VALIDATED
-------------------- -------------------- ---------- --------------------
SALES_CHANNEL_FK R DISABLED NOT VALIDATED
SQL> alter table SALES disable validate constraint SALES_CHANNEL_FK;
Table altered.
SQL> select constraint_name,constraint_type,status,validated from user_constraints where table_name='SALES' and constraint_type='R' and CONSTRAINT_NAME='SALES_CHANNEL_FK';
CONSTRAINT_NAME CONSTRAINT_TYPE STATUS VALIDATED
-------------------- -------------------- ---------- --------------------
SALES_CHANNEL_FK R DISABLED VALIDATED
SQL> alter table SALES enable novalidate constraint SALES_CHANNEL_FK;
Table altered.
SQL> select constraint_name,constraint_type,status,validated from user_constraints where table_name='SALES' and constraint_type='R' and CONSTRAINT_NAME='SALES_CHANNEL_FK';
CONSTRAINT_NAME CONSTRAINT_TYPE STATUS VALIDATED
-------------------- -------------------- ---------- --------------------
SALES_CHANNEL_FK R ENABLED NOT VALIDATED
SQL> alter table SALES enable validate constraint SALES_CHANNEL_FK;
Table altered.
SQL> select constraint_name,constraint_type,status,validated from user_constraints where table_name='SALES' and constraint_type='R' and CONSTRAINT_NAME='SALES_CHANNEL_FK';
CONSTRAINT_NAME CONSTRAINT_TYPE STATUS VALIDATED
-------------------- -------------------- ---------- --------------------
SALES_CHANNEL_FK R ENABLED VALIDATED
以上是“数据库中约束的validate和able怎么用”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!