Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2012
    Posts
    9

    Unanswered: Oracle FK relationship question

    Another quick Oracle question. I created a primary table with a single primary key with the following structure:

    Create table SERVERLIST
    ( "SERVER_ID" VARCHAR2(10 BYTE) ...)

    ALTER TABLE "APSOM"."SERVERLIST" ADD CONSTRAINT "XPKSERVERLIST" PRIMARY KEY ("SERVER_ID")

    and I created another table with 2 primary keys that I would like to reference the SERVERLIST table

    CREATE TABLE "CPULIST"
    ( "CPU_ID" VARCHAR2(10 BYTE),
    "SERVER_ID" VARCHAR2(10 BYTE), ...)

    ALTER TABLE "APSOM"."CPULIST" ADD CONSTRAINT "CPULIST_PK" PRIMARY KEY ("CPU_ID", "SERVER_ID")

    I tried to create a foreign key relationship with the SERVER_ID field of the CPULIST table to the same field of the SERVERLIST table, and it failed. How can I get this to work??

    Thanks,

    Patrick Quinn
    Operations
    Turning Point Global Solutions

  2. #2
    Join Date
    Jun 2004
    Posts
    796
    Provided Answers: 1
    How can I get this to work??
    Well, without more information, your chances are pretty low.

    What did you type?
    What was the exact error message?
    90% of users' problems can be resolved by punching them - the other 10% by switching off their PCs.

  3. #3
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    You should have posted your SQL*Plus session so that we could see what you exactly did and how Oracle responded. Let my copy/paste be a guide for your future messages.
    Code:
    SQL> create table serverlist
      2    (server_id   varchar2(10),
      3     server_name varchar2(20)
      4    );
    
    Table created.
    
    SQL> alter table serverlist add constraint pk_sl primary key (server_id);
    
    Table altered.
    
    SQL> create table cpulist
      2    (cpu_id       varchar2(10),
      3     server_id    varchar2(10),
      4     freq         number
      5    );
    
    Table created.
    
    SQL> alter table cpulist add constraint pk_cl primary key (cpu_id, server_id);
    
    Table altered.
    
    SQL> alter table cpulist add constraint fk_cl_sl foreign key (server_id)
      2    references serverlist (server_id);
    
    Table altered.
    
    SQL>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •