Oracle 10g ,举一个是唯一索引但不是唯一约束的例子,万分感谢!!!

来源:百度知道 编辑:UC知道 时间:2024/06/21 23:57:06
我知道唯一约束一定是唯一索引

--4.索引(INDEX)
--4.1 唯一(unique)索引
--格式:
create unique index <名称>
on 表(列);

create unique index i_club_unique
on club(club_id);

--4.2 反向(reverse)索引:字段唯一性很好的时候可以创建
--格式:
create index <名称>
on 表(列) reverse

--4.3 位图(bitmap)索引:字段唯一性很差的时候可以创建
--格式:
create bitmap index <名称>
on 表(列)

Oracle中唯一索引和唯一约束一定是同时存在的。

1. 在建表时如果指定唯一约束,系统自动建一个同名的唯一索引,因为在插入数据时,Oracle不想去搜索整个表来确定所插入的值是否已经存在,而是搜索一个唯一索引来有效地达到目的。
drop table tz8;
create table tz8 (id varchar2(2) unique);
insert into tz8(id) values('1');
insert into tz8(id) values('1');
ORA-00001: unique constraint (RMS11DEV.SYS_C0074821) violated

2. 如果建表时没指定唯一约束,在唯一索引建立后,重复的值同样不能被插入表中。虽然dba_constraints中不存在一个对应的约束,但是报错时会使用唯一索引的名字。
drop table tz8;
create table tz8 (id varchar2(2));
create unique index tz8i1 on tz8(id) ;
insert into tz8(id) values('1