Many to many using a primary-key and foreign-key relationship
SQL> CREATE TABLE Course
2 (course_id VARCHAR2(10) NOT NULL,
3 course_name VARCHAR2(20),
4 PRIMARY KEY (course_id));
Table created.
SQL>
SQL> CREATE TABLE emp
2 (stud_id VARCHAR2(10) NOT NULL,
3 stud_name VARCHAR2(20),
4 PRIMARY KEY (stud_id));
Table created.
SQL>
SQL> CREATE TABLE Enrolls_in
2 (course_id VARCHAR2(10) NOT NULL,
3 stud_id VARCHAR2(10) NOT NULL,
4 PRIMARY KEY (course_id, stud_id),
5 FOREIGN KEY (course_id) REFERENCES Course (course_id)
6 ON DELETE CASCADE,
7 FOREIGN KEY (stud_id) REFERENCES emp (stud_id)
8 ON DELETE CASCADE);
Table created.
SQL>
SQL> drop table Course cascade constraints;
Table dropped.
SQL> drop table emp cascade constraints;
Table dropped.
SQL> drop table Enrolls_in;
Table dropped.
SQL>
Related examples in the same category