I have a table where in a column i have non unique code
what i want is to implement primary key on this column for only new rows inserted not on already existing non unique codes in that column.
not sure what are your requirements but in datawarehouese you can play around with alter table xxx enable constraint yyy novalidate (by default it's validate) but that is to use after a batch data load not for everyday OLTP databases
it{s used in enabling and disabling constraints, I dont think it works with adding constraints, also it works for 8i so if you are using lower versions then forget it
I am using oracle8i I tried as u said by enable & disable process is written below :
SQL> select * from v$version ;
BANNER
---------------------------------------------------------
Oracle8i Release 8.1.5.0.0 - Production
PL/SQL Release 8.1.5.0.0 - Production
CORE Version 8.1.5.0.0 - Production
TNS for 32-bit Windows: Version 8.1.5.0.0 - Production
NLSRTL Version 3.4.0.0.0 - Production
SQL> insert into aa values('11','anuj2') ;
insert into aa values('11','anuj2')
*
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.PK_1) violated
1* alter table aa disable constraint pk_1
SQL> /
Table altered.
SQL> insert into aa values('11','anuj2') ;
1 row created.
SQL> commit ;
Commit complete.
SQL> alter table aa enable constraint pk_1 ;
alter table aa enable constraint pk_1
*
ERROR at line 1:
ORA-02437: cannot validate (SCOTT.PK_1) - primary key violated
Re: I am using oracle8i & output on enable & disable
Originally posted by anujpathak
SQL> alter table aa enable constraint pk_1 ;
alter table aa enable constraint pk_1
*
ERROR at line 1:
ORA-02437: cannot validate (SCOTT.PK_1) - primary key violated
[Edited by anujpathak on 04-15-2002 at 07:14 AM]
Hmm I thought I mentioned use novalidate clause in my previous post... not that hard to read man just have a closer look
SQL> insert into aa values ('11','anuj2') ;
insert into aa values ('11','anuj2')
*
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.PK_1) violated
SQL> alter table aa disable constraint pk_1 ;
Table altered.
SQL> insert into aa values ('11','anuj2') ;
1 row created.
SQL> alter table aa enable constraint pk_1 novalidate ;
alter table aa enable constraint pk_1 novalidate
*
ERROR at line 1:
ORA-00933: SQL command not properly ended
Bookmarks