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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:58:54+00:00 2026-06-17T16:58:54+00:00

this question is applicable on different RDBMS : MySQL and SQL Server I’ve been

  • 0

this question is applicable on different RDBMS: MySQL and SQL Server

I’ve been searching for this all night and I can’t find it on the net. My problem is all about uniqueness and foreign keys. Consider the following schema:

CREATE TABLE Male
(
    StudentID INT,
    FirstName VARCHAR(20) NOT NULL,
    MiddleName VARCHAR(20) NOT NULL,
    LastName VARCHAR(20) NOT NULL,
    -- other columns ...
    CONSTRAINT male_PK PRIMARY KEY (StudentID),
    CONSTRAINT male_UQ UNIQUE (FirstName, MiddleName, LastName)
);

CREATE TABLE Female
(
    StudentID INT,
    FirstName VARCHAR(20) NOT NULL,
    MiddleName VARCHAR(20) NOT NULL,
    LastName VARCHAR(20) NOT NULL,
    -- other columns ...
    CONSTRAINT Female_PK PRIMARY KEY (StudentID),
    CONSTRAINT Female_UQ UNIQUE (FirstName, MiddleName, LastName)
);

CREATE TABLE ClassList
(
    ClassID INT,
    Name VARCHAR(30),
    ClassYear INT,
    -- other columns ...
    CONSTRAINT ClassList_PK PRIMARY KEY (ClassID),
    CONSTRAINT ClassList_UQ UNIQUE (Name, ClassYear)
);

The reason why table Male and Female are separated is because they are maintained by different sql accounts.


The problem now is the Association Class.

CREATE Student_Class
(
    SudentID INT,
    ClassID INT,
    CONSTRAINT tb_UQ UNIQUE (StudentID, ClassID)
)

So my questions are:

  • How can I set the uniqueness of the StudentID from both tables Male and Female. I can’t find that on the net.
  • How can I enforce Foreign Key constraints in which the value column of the association class table come from two tables: Male and Female?

Suggestions are also Accepted.

Thank You

  • 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-17T16:58:55+00:00Added an answer on June 17, 2026 at 4:58 pm

    I don’t think it’s a great idea to let user privileges dictate your schema but if you have to then I think the idea mentioned by HerpaMoTeH is a good one. A third table with id, gender and with the id used as an FK in the gender specific tables and student_class.

    Another solution is to just split your student_class table into two:
    male_student_class and female_student_class

    Alternatively you could create 2 sets of stored procedures (male and female) for CRUD operations on a single student table. Then you would deny priviliges to the actual table for your users but grant them access to the appropriate set of stored procedures. Your schema would be simplified to:

    CREATE TABLE Student
    (
        StudentID INT,
        GenderId INT,
        FirstName VARCHAR(20) NOT NULL,
        MiddleName VARCHAR(20) NOT NULL,
        LastName VARCHAR(20) NOT NULL,
        -- other columns ...
    
    );
    
    
    CREATE Student_Class
    (
       SudentID INT,
       ClassID INT,
      CONSTRAINT tb_UQ UNIQUE (StudentID, ClassID)
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this question's been asked before, but I can't seem to find an
This question was originally using MySQL 5.1.44, but is applicable to MySQL 8.0+ too.
This question had been asked in some form before, but I could not find
This question is about Unity Container but I guess it is applicable to any
This question is specifically about PHP, but I'm guessing it might be applicable to
I have two classes [applicable to this question]. The first, XYAxes2 , extends FrameworkElement
This question was asked before but the solution is not applicable in my case.
I know a similar question has been posted before but I think this is
I'm designing a game, but this question is applicable to any situation that requires
i have asked this question before but the answer received was not applicable in

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.