Reputation: 53
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
Reputation: 50077
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