ORA-01452: cannot CREATE UNIQUE INDEX; duplicate keys found
建unique索引時遇到ORA-01452錯誤,如下:
SQL> create unique index uk_union_col on CFG_PERF_FORMULA(vendor,version,ne_type,att_enname); create unique index uk_union_col on CFG_PERF_FORMULA(vendor,version,ne_type,att_enname) ORA-01452: cannot CREATE UNIQUE INDEX; duplicate keys found SQL> select vendor,version,ne_type,att_enname 2 from cfg_perf_formula 3 group by vendor,version,ne_type,att_enname 4 having count(*)>1; VENDOR VERSION NE_TYPE ATT_ENNAME ---------- -------------------- ---------- ---------------------------------------------------------------- ZY0000 4 UPQUALIITYFLUCTVALUE ZY0000 2 BADCOVER_CELL_PER SQL> / VENDOR VERSION NE_TYPE ATT_ENNAME ---------- -------------------- ---------- ----------------------------------------------------------------- SQL> create unique index uk_union_col on CFG_PERF_FORMULA(vendor,version,ne_type,att_enname); Index created 這種錯誤的處理其實可以考慮幾種方法: 資料表裡要建的這幾列有重複的值,要麼 1、刪除重複值,然後再建唯一索引 2、就不建唯一索引 3、或指定deferrable novalidate不校驗表裡已存在資料,只對以後的資料有影響。 如: SQL> create table t(id number);
Table created.
SQL> insert into t values(1);
1 row created.
SQL> insert into t values(1);
1 row created.
SQL> commit;
Commit complete.
SQL> alter table t add constraint uk_t unique(id) deferrable novalidate;
Table altered.
SQL> insert into t values(1); insert into t values(1) * ERROR at line 1: ORA-00001: unique constraint (ZHAOSS.UK_T) violated
SQL> insert into t values(2);
1 row created.
SQL> rollback;
Rollback complete.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29119536/viewspace-1660993/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ORA-02299: cannot validate (SSERVICE.UK_MSI_WDR_INPUT) - duplicate keys found
- ORA-02429: cannot drop index used for enforcement of unique/primary keyIndex
- Index Unique Scan (213)Index
- pk 、unique index 和 index 區別Index
- create index/create index online區別Index
- Sparse Indexes vs unique indexIndex
- CREATE BITMAP INDEXIndex
- INDEX UNIQUE SCAN,INDEX FULL SCAN和INDEX FAST FULL SCANIndexAST
- create index online 和create index 不同及注意點Index
- Unique Index和Normal Index差異經典對比IndexORM
- 再說Unique Index和Normal Index行為差異IndexORM
- hive orc表'orc.create.index'='true'與'orc.create.index'='false'HiveIndexFalse
- create index .. onlineIndex
- Unable to create git index lockGitIndex
- create index onlineIndex
- Create Index ...ONLINEIndex
- Create index with open on-line index creationIndex
- unique index與primary key的區別Index
- CREATE INDEX ......ONLINE分析Index
- create index , rebuild index troubleshooting 索引故障解決IndexRebuild索引
- Data Warehouse Guide閱讀筆記(六):unique constraint & unique indexGUIIDE筆記AIIndex
- [20171211]UNIQUE LOCAL(Partitioned)IndexIndex
- 高效的SQL(Index unique scan最優化)SQLIndex優化
- Q:[Vue warn]: Duplicate keys detected: ‘PAYACT‘. This may cause an update error.VueError
- create index online 與rebuild index onlineIndexRebuild
- create index online 與rebuild index onlineIndexRebuild
- CREATE INDEX index1 ON table1(col1)Index
- IllegalArgumentException: requirement failed: Corrupt index foundExceptionUIREMAIIndex
- (排坑) Cannot create property 'key' on boolean 'true'Boolean
- 唯一性索引(Unique Index)與普通索引(Normal Index)差異(上)索引IndexORM
- 唯一性索引(Unique Index)與普通索引(Normal Index)差異(中)索引IndexORM
- 唯一性索引(Unique Index)與普通索引(Normal Index)差異(下)索引IndexORM
- 索引唯一性掃描(INDEX UNIQUE SCAN)索引Index
- 在什麼情況下用index unique scansIndex
- vue報錯之Duplicate keys detected: '0'. This may cause an update error.VueError
- postgresql create index concurrently過程描述SQLIndex
- mysql中key 、primary key 、unique key 與index區別MySqlIndex
- MySQL online create index實現原理MySqlIndex