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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:25:58+00:00 2026-05-11T09:25:58+00:00

Ok. So I know what a primary key in DB is. If you have

  • 0

Ok. So I know what a primary key in DB is. If you have a table in a database, a primary key is a single value that is unique to each row in your table. For example:

id   | name    | whatever ------------------------- 1      Alice     .... 2      Bob       .... 45     Eve       .... 988    ....      .... 

So I need a good, simple example to explain what exactly a foreign key is. Because I just don’t get it 🙂


Edit: OK it’s pretty easy, I guess I was over-complicating the problem.

So one final question, the only restriction on foreign keys is that it they are a valid primary key value in the table I am referring to?

  • 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. 2026-05-11T09:25:59+00:00Added an answer on May 11, 2026 at 9:25 am

    A foreign key is a field that points to a primary key of another table.

    Example:

    Table Name - Users  UserID    UserName    UserRoleID 1         JohnD       1 2         CourtneyC   1 3         Benjamin    2  Table Name - UserRoles  UserRoleID    Desc 1             Admin 2             Moderator 

    You can see that Users.UserRoleID is a foreign key which points to the primary key UserRoles.UserRoleID

    The use of foreign keys makes setting up relationships on other tables simple, allowing you to link together the data of multiple tables in a nice way:

    Example:

    SELECT     a.UserID,      a.UserName,      b.Desc as [UserRole] FROM      Users a INNER JOIN          UserRoles b ON a.UserRoleID = b.UserRoleID 

    Output would then be:

    UserID    UserName    User Role 1         JohnD       Admin 2         CourneyC    Admin 3         Benjamin    Moderator 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a MySQL database I have a table with the following primary key PRIMARY
I have a database table and one of the fields (not the primary key)
I have a MySQL table with a primary key field that has AUTO_INCREMENT on.
Imagine I have this simple table: Table Name: Table1 Columns: Col1 NUMBER (Primary Key)
I have the following table: id INT (PRIMARY) score INT I'd like to know,
I have a table where I haven't explicitly defined a primary key, it's not
I have a database table with a unique string field and a couple of
I have a database table my code inserts a row here everytime user solves
I have a table that has an autoincrement surrogate key. I want to use
I currently have a closure table used for hierarchical data that has 5 million

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.