I've seen someone propose to solve this issue (single row) by adding a column with two constraints: it is unique AND is equal to (say) 1.
Yeah, I would kind of attack it with a unique index also. I would probably:
1. create a dummy field, say ID.
2. make ID a primary key
3. create an insert trigger that stuffs a "1" into the ID field unconditionally.
Code:SQL> create table xyz (id number(10) primary key, 2 f2 varchar2(6)); Table created. SQL> edit Wrote file afiedt.buf 1 create or replace trigger t1 2 before insert on xyz 3 for each row 4 begin 5 :new.id := 1; 6* end; SQL> / Trigger created. SQL> insert into xyz (f2) values ('foo'); 1 row created. SQL> insert into xyz(f2) values ('bar'); insert into xyz(f2) values ('bar') * ERROR at line 1: ORA-00001: unique constraint (SYSTEM.SYS_C005255) violated SQL> select * from xyz; ID F2 ---------- ------ 1 foo




Reply With Quote