Skip to content

Instantly share code, notes, and snippets.

@estysdesu
Last active July 21, 2019 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save estysdesu/9fe4be922feb729048a0a9af5871959e to your computer and use it in GitHub Desktop.
Save estysdesu/9fe4be922feb729048a0a9af5871959e to your computer and use it in GitHub Desktop.
[SQL: create table with many-to-many relationship] #constraint #postgres #many-to-many #sql
// vim: syntax=sql
-- many-to-many relationship needs join table
CREATE TABLE IF NOT EXISTS student_course (
student_id INTEGER,
course_id INTEGER,
PRIMARY KEY (student_id, course_id),
FOREIGN KEY (student_id) REFERENCES student (id),
FOREIGN KEY (course_id) REFERENCES course (id) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment