Last active
July 21, 2019 06:05
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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