Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6893345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:38:50+00:00 2026-05-27T06:38:50+00:00

Is it allowed in SQL to have a foreign key that is not a

  • 0

Is it allowed in SQL to have a foreign key that is not a primary key but a (multiple) unique key? To be specific:

[Table 1]

CREATE TABLE Session_Record(
c_id CHAR (3) NOT NULL
    REFERENCES Club_Record(c_id),
sess_id NUMBER (4) NOT NULL CHECK (sess_id >0)
room CHAR (4) NOT NULL,
UNIQUE(c_id, sess_id)
);

[Table 2]

CREATE TABLE SessionDuration__Record(
c_id CHAR (3) NOT NULL
    REFERENCES Club_Record(c_id),
sess_id NUMBER (4) NOT NULL CHECK (sess_id >0)
    REFERENCES Session_Record(sess_id),
day CHAR(9) NOT NULL,
duration NUMBER(3) NOT NULL,
UNIQUE(c_id, sess_id)
);

“c_id” is a primary key in the table Club_Record. But sess_id is not a primary key. It is a multiple candidate key in combination with c_id. Is this form of declaration allowed in SQL?. Because Oracle 10g is returning: “no matching unique or primary key for this column-list” for the (sess_id) foreign key statement.
Help is much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:38:50+00:00Added an answer on May 27, 2026 at 6:38 am

    Your SQL is invalid in a few different ways (missing a comma after the definition of Session_Record.sess_id; using day as an identifier without quoting it), but sticking just to the problem that you explicitly asked about — I’m guessing what you really want is this:

    CREATE TABLE SessionDuration__Record
    (
        c_id      CHAR(3)    NOT NULL  REFERENCES Club_Record(c_id),
        sess_id   NUMBER(4)  NOT NULL  CHECK (sess_id >0),
        "DAY"     CHAR(9)    NOT NULL,
        duration  NUMBER(3)  NOT NULL,
        UNIQUE(c_id, sess_id),
        FOREIGN KEY (c_id, sess_id) REFERENCES Session_Record(c_id, sess_id)
    );
    

    That is, you want to be sure that each (SessionDuration__Record.c_id, SessionDuration__Record.sess_id) corresponds to an existent (Session_Record.c_id, Session_Record.sess_id).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an SQL table with basically the following structure: PK (int, primary key),
I have a table Location that has a foreign key relationship to a Site.
SQL Azure not only requires each table to have a clustered index, but also
How do I create a MS SQL server user that only allowed to read
I'm currently working with MS SQL 2005, and have a table that has 17
I have a table in Sql Server that contain an int field price that
I hope this is allowed but I have a number of questions regarding Facebook
I have written a table-valued UDF that starts by a CTE to return a
I have a InsuranceDetails SQL table, one of the column is VIN whose type
I have a Text File (Sorry, I'm not allowed to work on XML files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.