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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:33:16+00:00 2026-05-23T09:33:16+00:00

Say I have two tables, a and b : a { pk as int

  • 0

Say I have two tables, a and b:

a {
 pk as int
 fk as int
 ...
}

b {
 pk as int
 ...
}

I want to join a and b in a query like so:

FROM a
JOIN b on a.fk = b.pk

Which of the following scenarios will be faster?

  1. a.fk is set up to be a foreign key on b.pk – b.pk is indexed
  2. a.fk is set up to be a foreign key on b.pk – b.pk is not indexed
  3. there is no relationship between the tables – b.pk is indexed
  4. there is no relationship between the tables – b.pk is not indexed

Bonus question – how much faster/slower will each of these scenarios be?

If you could back up your answer with a reference then that’d be awesome. 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-05-23T09:33:16+00:00Added an answer on May 23, 2026 at 9:33 am

    Best practice

    1. Foreign Keys are a relational integrity tool, not a performance tool. You should always create indexes on FK columns to reduce lookups. SQL Server does not do this automatically.
    2. As stated here Foreign keys boost performance

    Logically, this gives following ranking performance wise

    1. a.fk is set up to be a foreign key on b.pk – b.pk is indexed
    2. there is no relationship between the tables – b.pk is indexed
    3. a.fk is set up to be a foreign key on b.pk – b.pk is not indexed
    4. there is no relationship between the tables – b.pk is not indexed
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have two tables I want to join. Categories: id name ---------- 1
Let's say I have the following two tables: Fields FieldID INT FieldName NVARCHAR(50) Values
Lets say I have two tables tblA ( tableAID INT IDENTITY(1,1), foo VARCHAR(100)) tblB
I have several hosts from which i want to do the same query. So
Say I have two tables: mysql> show columns from profiles; +--------------+--------------+------+-----+---------+----------------+ | Field |
I have two tables like this Table Product ProductId - int <PK> ProductExpiry -
I have two tables, say Table A and Table B. I want to have
Say I have two tables, Parent and Child. Parent has a MaxChildren (int) field
Say I have two tables as outlined below: mysql> show columns from ping; +------------+------------------+------+-----+---------+----------------+
Say I have an MSSQL table with two columns: an int ID column that's

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.