Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2013
    Posts
    8

    Unanswered: Column Reference Problem

    I want to create 2 tables where the other table would reference a column from the first table but when i try to run it, it gives me an error saying

    "does not identify a unique constraint of the parent table or nickname"

    Here is my code:

    Code:
    Create Table XML_COLLEGE
    (
    CLCODE  CHAR(5) NOT NULL,
    CLDEAN  INT     NOT NULL,
    CLINFO  XML,
    PRIMARY KEY(CLCODE,CLDEAN)
    )
    
    Create Table XML_STUD
    (
    IDNO        CHAR(8) NOT NULL PRIMARY KEY,
    STUDINFO    XML,
    CLCODE      CHAR(5) NOT NULL,
    FOREIGN KEY(CLCODE)
    REFERENCES XML_COLLEGE(CLCODE)
    )
    I want to reference the column CLCODE but it won't let me do it. Do I have to change something with my code? I am really confused right now.
    Last edited by intes2013; 10-04-13 at 05:59. Reason: grammar

  2. #2
    Join Date
    Apr 2012
    Posts
    1,035
    Provided Answers: 18
    The foreign key must match the primary key in terms of the number+types of columns. (in your example, you have a composite primary key - 2 columns, but your foreign key has a single column).

  3. #3
    Join Date
    Oct 2013
    Posts
    8
    Quote Originally Posted by db2mor View Post
    The foreign key must match the primary key in terms of the number+types of columns. (in your example, you have a composite primary key - 2 columns, but your foreign key has a single column).

    Thank you i got everything to work now! Here is my updated code:

    Code:
    Create Table XML_COLLEGE
    (
    CLCODE  CHAR(5) NOT NULL,
    CLDEAN  INT,
    CLINFO  XML,
    PRIMARY KEY(CLCODE)
    )
    
    Create Table XML_STUD
    (
    IDNO        CHAR(8) NOT NULL PRIMARY KEY,
    STUDINFO    XML,
    CLCODE      CHAR(5) NOT NULL,
    FOREIGN KEY(CLCODE)
    REFERENCES XML_COLLEGE(CLCODE)
    )
    I only made one primary key instead of two. Thanks a lot. I have learned something new today.

Posting Permissions

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