oracle10g_exceptions异常表_记录违犯pk_unique key约束信息

--构建一个存储违犯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

请使用浏览器的分享功能分享到微信等