Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

SQL Refrencing a Foreign Key

  1. Sep 9, 2011 #1

    JOZ

    User Avatar

    Hi im trying to create the tables below and having problems with the timeLog table referencing allocation, when I put it into the modified form of Oricle my University uses it dosent like me refrencing the refrenced values it spits out the error:
    Code (Text):
    ORA-02256: number of referencing columns must match referenced columns
    Is it even possible to refrence a value thats already being refrenced?
    Is there a way to refrence both the EmpID and ProjID together from allocation so that the EmpID, ProjID pair has to exist in allocation to be used in timeLog

    Code (Text):
    CREATE TABLE employee (
        EmpID       number PRIMARY KEY,
        EmpName     varchar2(30),
        Gender      varchar2(1));
       
    CREATE TABLE project (
        ProjID       varchar2(2) PRIMARY KEY,
        Description  varchar2(30),
        Budget  number);
       
    CREATE TABLE allocation (
        EmpID       number references employee,
        ProjID      varchar2(2) references project,
        HourlyRate  number(5,2),
        PRIMARY KEY (EmpID, ProjID));
       
    CREATE TABLE timeLog (
        EmpID       number references allocation,
        ProjID      varchar2(2) references allocation,
        WeekNo      number,
        HrsWorked   number,
        PRIMARY KEY (EmpID, ProjID, WeekNo));
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: SQL Refrencing a Foreign Key
  1. SQL basics (Replies: 4)

  2. SQL relationships (Replies: 3)

  3. Sql join? (Replies: 4)

  4. SQL Help (Replies: 2)

Loading...