关于CONSTRAINT

1.可延迟约束

SELECT   * FROM   user_constraints 查询所有约束

alter table child add constraint  fk_child foreign key (parent_name)

references parent (parent_name) deferrable ;

取消延迟:

set constraint fk_child immediate ;

2.检查约束

   alter table temp add constraint ck_temp_age check ((age>0) and (age <= 125))

3.自引用约束

   alter table professors add constraint fk_professors_prof_name foreign key (dept_head)

   references professors (prof_name);--当然prof_name需为primary key;

4.禁用/激活约束(禁用/激活约束会引起删除和重建索引的操作)
alter table employees disable/enable unique email
alter table employees disable/enable constraint emp_ename_pk
alter tabel employees modify constraint emp_pk disable/enable
alter tabel employees modify constraint emp_ename_phone_uk disable/enable

ALTER TABLE employees DROP CONSTRAINT emp_deptno_fk;删除约束

5.级联删除

   alter table students add constraint fk_students_state foreign key (state) references state_lookup(state) on delete cascade ;

6.多列属性约束

   alter table students add constraint uk_students_lic unique (state,license) ;

你可能感兴趣的:(CONSTRAINT)