Josh King
Josh King

Reputation: 53

invalid ALTER TABLE option when trying to add fk

ALTER TABLE OtherCharges
(
    ADD FOREIGN KEY (BookingID) REFERENCES Bookings(BookingID)
);

Above is the code I have and the error I am getting is "invalid ALTER TABLE option" any help would be appreciated.

Upvotes: 0

Views: 1145

Answers (1)

You might want to have a look at the SQL Reference. To add a foreign key you'd use

ALTER TABLE OTHERCHARGES
  ADD CONSTRAINT OTHERCHARGES_FK1
    FOREIGN KEY (BOOKING_ID) REFERENCES BOOKINGS(BOOKING_ID)
      ON DELETE NO ACTION;

Always a good idea to name your constraints something reasonable but simple. Also, for FK's always specify an ON DELETE action, even if it's NO ACTION - that way it's explicitly stated and easy to understand.

Upvotes: 2

Related Questions