I've created a table, defined as follows:
create table formula (
type char(1) default 'd'
check (type in ('d','o','w')),
)
I wanted to change the check constraint to also have the the option
for 't'.
It seems you can't do this by simply modifying the table:
SQL> alter table formula modify (
2 type char(1) default 'd' check (type in ('d','o','t','w')));
type char(1) default 'd' check (type in ('d','o','t','w')))
*
ERROR at line 2:
ORA-02253: constraint specification not allowed here
So I delved into my hefty Oracle8: The Complete Reference, and it
seems there is a nifty table that keeps track of all the constraints:
SQL> select constraint_name,search_condition from user_constraints
where table_name = 'FORMULA' and constraint_name = 'SYS_C005027';
CONSTRAINT_NAME SEARCH_CONDITION
--------------- ----------------
SYS_C005027 type in ('d','o','w')
So I know the Constraint name. I thought I could then simply update
it, but it doesn't seem to work:
SQL> update user_constraints set search_condition = 'type in
''d'',''o'',''t'',''w'')' where constraint_name = 'SYS_C005027';
update user_constraints set search_condition = 'type in
''d'',''o'',''t'',''w'')' where constraint_name = 'SYS_C005027'
*
ERROR at line 1:
ORA-01031: insufficient privileges
SQL> connect internal
Connected.
SQL> update user_constraints set search_condition = 'type in
''d'',''o'',''t'',''w'')' where constraint_name = 'SYS_C005027';
update user_constraints set search_condition = 'type in
''d'',''o'',''t'',''w'')' where constraint_name = 'SYS_C005027'
*
ERROR at line 1:
ORA-01779: cannot modify a column which maps to a non key-preserved
table
Deletion doesn't work either. Any ideas? The double quote thing is
correct, isn't it?
As always, I'm very appreciative of assistance! 😊