Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding multiple constraints in ORACLE using ALTER TABLE

Is there a way to add multiple constraints in Oracle at once using the ALTER TABLE command? I know it is possible with SQL server.

ALTER TABLE l_customer_order 
    ADD CONSTRAINT pk_l_customer_order 
        PRIMARY KEY (customer_order_id_hk),
    CONSTRAINT fk_customer_id_hk 
        FOREIGN KEY (customer_id_hk) 
        REFERENCES h_customers(customer_id_hk)
        ON DELETE CASCADE,
    CONSTRAINT fk_order_id_hk 
        FOREIGN KEY (order_id_hk) 
        REFERENCES h_orders(order_id_hk)
        ON DELETE CASCADE;

Error message:

Error report -
ORA-01735: invalid ALTER TABLE option
01735. 00000 -  "invalid ALTER TABLE option"
*Cause:    
*Action:
like image 544
Maeaex1 Avatar asked Sep 10 '26 02:09

Maeaex1


1 Answers

Place the constraints in parentheses:

create table t (
  c1 int, c2 int, c3 int
);

alter table t
  add ( 
    constraint pk 
      primary key ( c1 ),
    constraint ck 
      check ( c2 > 0 )
  );

select constraint_name 
from   user_constraints
where  table_name = 'T';

CONSTRAINT_NAME   
CK                 
PK     
like image 82
Chris Saxon Avatar answered Sep 13 '26 22:09

Chris Saxon