-
Hi,
Is composite reference key possible. If yes then
Can anybody provide me with composite reference key example.
When the going gets tough, the tough gets going
-
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Click Here to Expand Forum to Full Width
|
Bookmarks