--构建一个存储违犯pk及unique key约束的记录表,须包括列:table_name,owner,rowid,constraint_name
SQL> alter table test enable constraint pk_test exceptions into exceptions; --通过alter 开启约束且exceptions into 以上创建的表(表名可随意)
alter table test enable constraint pk_test exceptions into exceptions
*
ERROR at line 1:
ORA-02437: cannot validate (SCOTT.PK_TEST) - primary key violated
SQL> select a.* --用此sql可查询开启pk 及unique 约束违犯约束的相关记录,根据业务另行delete重复记录或更新操作
2 from test a,exceptions
3 where a.rowid=exceptions.row_id;
DEPTNO DNAME LOC
---------- -------------- -------------
40 it beijing
40 OPERATIONS BOSTON
小结:
exceptions表不会自动清除以有记录,须truncate
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9240380/viewspace-670942/ ,如需转载,请注明出处,否则将追究法律责任。