alter table table_name drop constraint constraint_name;----drop 约束
alter table table_name add constraint constraint_name primary key(column_name1,column_name2);-----创建主键
alter table table_name add constraint constraint_name unique(column_name1,column_name2);---创建唯一约束
/*创建外键约束*/
alter table table_name add constraint constraint_name foreign key(column_name1) references table_name(column_name1);
/*不效验老数据,只约束新的数据[enable/disable:约束/不约束新数据;novalidate/validate:不对/对老数据进行验证]*/
alter table table_name add constraint constraint_name check(column_name like 'B%') enable/disable novalidate/validate;
/*修改约束条件,延时验证,commit时验证*/
alter table table_name modify constraint constraint_name initially deferred;
/*修改约束条件,立即验证*/
alter table table_name modify constraint constraint_name initially immediate;
alter session set constraints=deferred/immediate;
/*drop一个有外键的主键表,带cascade constraints参数级联删除*/
drop table table_name cascade constraints;
/*当truncate外键表时,先将外键设为无效,再truncate;*/
truncate table table_name;
/*设约束条件无效*/
alter table table_name disable constraint constraint_name;
alter table table_name enable novalidate constraint constraint_name;
/*将无效约束的数据行放入exception的表中,此表记录了违反数据约束的行的行号;在此之前,要先建exceptions表*/
alter table table_name add constraint constraint_name check(column_name >15) enable validate exceptions into exceptions;
/*运行创建exceptions表的脚本*/
start $ORACLE_HOME/rdbms/admin/utlexcpt.sql;
/*获取约束条件信息的表或视图*/
select * from user_constraints/dba_constraints/dba_cons_columns;