oracle在已有重复数据的表中某列加上唯一索引

有两种方法:
方法1、

alter table sk_data add (unique(longtime) deferrable enable novalidate)

sk_data为表名,longtime为需要加上唯一索引的列。注意加上了deferrable

方法2、

create index u_longtime on sk_data(longtime) 

先在需要增加唯一索引的列上加上普通索引

alter table sk_data add constraint aa_u unique(longtime) enable novalidate

 唯一索引名可以与之前加的普通索引名不同

猜你喜欢

转载自jilin.iteye.com/blog/1922103