reference key
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: reference key

  1. #1
    Join Date
    Feb 2001
    Posts
    103
    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

  2. #2
    Join Date
    Jan 2001
    Posts
    2,828

    Talking

    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
  •  



Click Here to Expand Forum to Full Width