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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:45:50+00:00 2026-05-25T10:45:50+00:00

I am reading a book called MySQL developer’s library by Paul DuBois and in

  • 0

I am reading a book called “MySQL developer’s library” by Paul DuBois and in the book he says:

CREATE TABLE score
(
student_id INT UNSIGNED NOT NULL,
event_id INT UNSIGNED NOT NULL,
score INT NOT NULL,
PRIMARY KEY (event_id, student_id),
INDEX (student_id),
FOREIGN KEY (event_id) REFERENCES grade_event (event_id),
FOREIGN KEY (student_id) REFERENCES student (student_id)
) ENGINE = InnoDB;

We made the combination of the two columns a PRIMARY KEY.
This ensures that we won’t have duplicate scores for a student
for a given quiz or test. Note that it’s the combination of
event_id
and student_id that is unique. In the score table, neither value
is unique
by itself. There will be multiple score rows for each event_id
value
(one per student), and multiple rows for each student_id value
(one for each
quiz and test) taken by the student

What is not clear to me is the combining two columns as one primary key… Meaning, I am having a hard time visualizing what is actually going on under the hood… It’s taking a collection of numbers [95, 210] for example and using that as a “key”… Is it appropriate to think of a primary key as a key to a hash?

Previously I always thought of primary keys as nothing more than unique ids for a table.. but now in this context, I am finding myself what a primary key actually is doing. Can anyone give me the low down on SQL keys?

  • 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-25T10:45:51+00:00Added an answer on May 25, 2026 at 10:45 am

    A Primary Key is essentially it is a unique key with a not null constraint.
    (as already mentioned, it is used to enforce referential integrity of your data)

    It is simply a different type of primary key:

    surrogate key / artificial key = usually a sequential number

    http://en.wikipedia.org/wiki/Surrogate_key

    natural key = column(s) that make the row unique

    http://en.wikipedia.org/wiki/Natural_key

    and here http://www.geeksengine.com/database/design/primary-key-constraint.php is a really good explanation of the differences.

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

Sidebar

Related Questions

I am reading a book called Teach Yourself C in 21 Days (I have
All. I am reading a book called and one of the idea is Don't
I've been reading a book which is in C#. I'm a VB.NET developer (and
I was reading a book called C# Yellow Book by Rob Miles when I
I am reading the book High Performance MySQL and messing around with a new
I am reading book called C++ coding standard By Herb Sutter, Andrei Alexandrescu and
While reading a book called Let us C I read that a function showbit()
Am reading an O'Reilly book called Learning WCF and in chapter one, it mentions:
I am reading a great book called Swing: A Beginner's guide. There is this
Right now I'm reading a beginner-level book called 'Programming Embedded Systems'. It has one

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.