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.
x
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);