Skip to content
Advertisement

Alter Table Foreign Key

I’m trying to add barista_grade_id to the baristas table as a foreign key and I’ve looked every where on what syntax to use and it seems to be unanimous that this is the correct way.

ALTER TABLE baristas
ADD FOREIGN KEY barista_grade_id REFERENCES barista_grade(barista_grade_id)

I did it before this and it worked. but because of some mistakes I deleted it and redo it again, but for whatever reason it says that it’s a syntax error.

Advertisement

Answer

The format is like this:

ALTER TABLE baristas
ADD CONSTRAINT FOREIGN KEY (barista_grade_id) REFERENCES barista_grade (barista_grade_id);
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement