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

  • SEARCH
  • Home
  • 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 8322953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:33:32+00:00 2026-06-08T23:33:32+00:00

I am making a database of students in one school.Here is what I have

  • 0

I am making a database of students in one school.Here is what I have so far:
enter image description here

If you don’t like reading jump to the “In short” part

The problem is that I’m not happy with this design. I want the combination of grade, subgrade and id_class to be unique and to serve as a primary key for the students table.
I can remove the student_id and make a composite key from the 3 but I don’t want that either. Maybe I should make another table lets say combination_id where grade, subgrade and id_class are foreign keys and there is one extra column comb_id that serves as ID for the table. And all the columns will be Primary Keys. But the problem is that those 3 columns can still repeat because of that extra column (comb_id). For example I can have the same grade, subgrade and class_id but different comb_id which will make the row valid because of the composite key of the 4 columns of the table (combination_id).

In short I want students_id to remain the only primary key of the table but to be a foreign key to another table which is somehow unique combination of grades, subgrade and class_id.

If I was not clear enough ask in the comments below and thank you in advance.

PS I’m sorry for the indescriptive title but I’m bad at naming

EDIT 1:
To be more clear:
grade can be 1 to 12
subgrade can be a to j
id_class can be 1 to 30 and it is your number in class

So a student can be from 7b class and his number in class – 5

  • 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-08T23:33:33+00:00Added an answer on June 8, 2026 at 11:33 pm

    Don’t mix the concepts of unique keys and primary keys. You can very well add a unique key spanning the three columns grades, subgrade and class_id. That way, no two rows could have the same values for these three columns. As you write that you don’t want to have these three as a composite primary key, I’m not sure whether a composite unique supplemental key would be any better. If not, you’ll have to clarify when composite keys are acceptable.

    To create a unique key, you can use the following SQL statement:

    ALTER TABLE students ADD UNIQUE gsc (grades, subgrade, class_id);
    

    The word gsc there is just a name I made up from the initials of the key columns; use whatever name you want, as it hardly matters unless you want to identify the key in some EXPLAIN output or similar.

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

Sidebar

Related Questions

I just started making a database for my website so I am re-reading Database
I'm building a database for making hotel reservations. One table called reservations holds the
I'm making an update to our database and would like to update rows that
I'm making a database and have a table structured as follows Att1 Att2 Att3
I have tried making two database tables wp_marketing and wp_email . I have a
I have a sample database like below, and I want to display only the
I am making a database for a client where I will have an Account
I'm making a database in EF4.1 Code First. I have a table, MedicalPlan, with
I am making a mock database and I have a student table, student_class linking
I'm making a database view in MS SQL server 2008 R2. One of the

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.