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 7875253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:57:06+00:00 2026-06-03T02:57:06+00:00

Just a quick question regarding Junction tables in Oracle SQL. I understand their functionality

  • 0

Just a quick question regarding Junction tables in Oracle SQL. I understand their functionality and their role in a ‘many to many’ relationship but what about a ‘one to many’ relationship? I have two tables, Employees and Positions. Each Employee can only hold one position, however each each position can have many employees. e.g. John Doe can only be a sales executive, however there are 4 sales executives in the company. This is how I have it coded so far:

CREATE TABLE Positions (
position_id NUMBER(2) NOT NULL,
position_name VARCHAR2(25) NOT NULL,
CONSTRAINT pk_position PRIMARY KEY(position_id)
);

CREATE TABLE Employee (
emp_id NUMBER(3) NOT NULL,
emp_name VARCHAR2(30) NOT NULL,
emp_position NUMBER(2) NOT NULL,
emp_salary NUMBER(5) NOT NULL,
CONSTRAINT pk_employee PRIMARY KEY(emp_id),
CONSTRAINT fk_emp_pos FOREIGN KEY (emp_position) 
REFERENCES Position(position_id)
);

CREATE TABLE pos_emp (
position_id NUMBER(2) NOT NULL,
emp_id NUMBER(3) NOT NULL,
CONSTRAINT pk_pos_emp PRIMARY KEY(position_id, emp_id)
);

Is this correct? Is there a need for:
a. The foreign key in the Employee table?
b. The junction table?

I want to enforce the one employee to one role relationship in the employee table while being able to have the one role to many employees relationship in the junction table.

Hope this makes sense

  • 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-06-03T02:57:07+00:00Added an answer on June 3, 2026 at 2:57 am

    The relations you have set up is a Many-Many relation. So if you want a one to many. Then the most common way is to skip the pos_emp and have the foreign key directly in Employee. So that the table looks something like this:

    CREATE TABLE Employee (
    emp_id NUMBER(3) NOT NULL,
    emp_name VARCHAR2(30) NOT NULL,
    emp_position NUMBER(2) NOT NULL,
    emp_salary NUMBER(5) NOT NULL,
    position_id NUMBER(2) NOT NULL,
    ...
    

    EDIT

    I have my employee table set up like that in my code. Will having the
    Position_id in the Employee table as the foreign key be enough to
    enforce each position having many employees?

    If the position_id in the Employee do not allow nulls then you cannot add a Employee without a position. That means that if you are trying to insert a Employee without a position you will get an exception that the foreign relation is not satisfy.

    But you need to check it in code so that when you add a Employee the position_id has a value. So you do not send the insert to that database if it do not have a value. Because that is a unnecessarily database call.

    And another interesting point is what should happened if you remove a Employee? Should you remove the Employee related to that position? If the answer is yes. You might consider to have a cascade delete from the position table. Otherwise you might need a trigger for it.

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

Sidebar

Related Questions

Just a quick question regarding re-useable code. Ive lately been trying to modularise my
just a quick question regarding C and processes. In my program, I create another
I just had a quick question regarding loops in Ruby. Is there a difference
I just have a quick best practice question regarding custom cells in a UITableView.
Just a quick question. I understand that Singleton patterns can be extended and that
Just a quick question regarding the split function How can I split my string
I have got just a quick question regarding the header hierarchy when using HTML5
Just a quick question. If I learn how to develop apps for IPhone using
just a quick question: I am a CS undergrad and have only had experience
just a quick question, if I have a matrix has n rows and m

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.