Hi,
Is composite reference key possible. If yes then
Can anybody provide me with composite reference key example.
Printable View
Hi,
Is composite reference key possible. If yes then
Can anybody provide me with composite reference key example.
yeah its possible to have composite foreign keys have a look at the code below.
parent table
-----------------------------
CREATE TABLE classes (
department CHAR(3),
course NUMBER(3),
CONSTRAINT classes_department_course
PRIMARY KEY (department, course),
);
--------------------------------------
child table
-----------------------------------------
CREATE TABLE registered_students (
student_id NUMBER(5) NOT NULL,
department CHAR(3) NOT NULL,
course NUMBER(3) NOT NULL,
grade CHAR(1),
CONSTRAINT rs_student_id
FOREIGN KEY (student_id) REFERENCES students (id),
CONSTRAINT rs_department_course
FOREIGN KEY (department, course)
REFERENCES classes (department, course)
);
only thing si number and datatype of columns should and must match