0
votes

Alter table residential add constraint pk_restype primary key (customerID) REFERENCES customer(customerID);

I'd like to set primary key constraints on 'residential' table but ORA-01735 error appears indicating "invalid ALTER TABLE option". I've also tried the following to make foreign key relation but it also comes up as the same error code.

Alter table residential add constraint fk_restype foreign key (customerID, customertype) REFERENCES customer(customerID, customertype);

1

1 Answers

0
votes

Your problem is you are creating a primary key as if it is a foreign key.

The proper PK syntax is:

alter table residential add constraint pk_restype primary key (customerID);

No references clause is allowed in a Primary Key, on a Foreign Key.

The PK says this column customerID is unique and identifies a unique row in the residential table. It has nothing to do with referencing another table.

A FK would be:

alter table tab_child add constraint fk_child FOREIGN key (child_id)
   REFERENCES tab_parent(id);

The FK says a column child_id in table tab_child refers to and is constrained by the column id in table tab_parent