pc网站建设建站模板/百度竞价恶意点击软件
四.修正约束数据
当给一个表作主键约束时,因为已存数据不满足约束规则,会提示错误信息,些时必须对数据进行修正
要修正数据先找出不满足约束的数据
如下表,有不满足约束的数据
SQL> select * from t;
I V
---------- ------------------------
1 2
3 4
15 12
15 10
如果一个表数据量多可通过如下方法查找
SQL> alter table t drop constraint pk_i;
Table altered.
SQL>conn y / 123
SQL> @$Oracle_HOME/rdbms/admin/utlexcpt.sql
Table created.
SQL> alter table t add constraint pk_i primary key (i) exceptions into exceptions;
SQL>select * from t where rowid in (select row_id from exceptions) ;
I V
---------- ------------------------
15 12
15 10
找到了重复的记录
修正
SQL>update t set i=10 where v=12;
SQL> select * from t;
I V
---------- ----------
1 2
3 4
10 12
15 10
再建主键约束
SQL>alter table t add constraint pk_i primary key (i) ;
Table altered.