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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:28:45+00:00 2026-05-29T23:28:45+00:00

Are Foreign Keys in SQL Server 2008 are automatically indexed with a value? For

  • 0

Are Foreign Keys in SQL Server 2008 are automatically indexed with a value? For Example. if I add a value in my Primary key (or auto incremetend) in may parent table will the table that has a foreign key referenced to that key will automatically have the same value? or I Have to do it explicitly?

  • 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-29T23:28:46+00:00Added an answer on May 29, 2026 at 11:28 pm

    No, if you create a foreign key in a child table, it will not automatically get populated when a parent row gets inserted. If you think about this it makes sense. Let’s say you have a table like:

    CREATE TABLE dbo.Students
    (
      StudentID INT IDENTITY(1,1) PRIMARY KEY,
      Name SYSNAME
    );
    
    CREATE TABLE dbo.StudentLoans
    (
      LoanID INT IDENTITY(1,1) PRIMARY KEY,
      StudentID INT FOREIGN KEY REFERENCES dbo.Students(StudentID),
      Amount BIGINT -- just being funny
    );
    

    What you are suggesting is that when you add a row to Students, the system should automatically add a row to StudentLoans – but what if that student doesn’t have a loan? If the student does have a loan, what should the amount be? Should the system pick a random number?

    Typically what will happen in this scenario is that you’ll be adding a student and their loan at the same time. So if you know the loan amount and the student’s name, you can say:

    DECLARE 
      @Name       SYSNAME = N'user962206', 
      @LoanAmount BIGINT = 50000,
      @StudentID  INT;
    
    INSERT dbo.Students(Name) 
      SELECT @Name;
    
    SELECT @StudentID = SCOPE_IDENTITY();
    
    INSERT dbo.StudentLoans(StudentID, Amount)
      SELECT @StudentID, @LoanAmount;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two SQL Server tables with Primary Keys (PK) and a Foreign Key
When setting up foreign keys in SQL Server, under what circumstances should you have
Nearly identical to Query a Table's Foreign Key relationships , but for SQL Server
Is there a way using SQL to list all foreign keys for a given
In SQL Server 2008, is there a way to insert rows while omitting those
In SQL Server 2008 I had remade the database structure similar to Access. I
This comes up a lot for me. In SQL Server 2008, I have 3
I'm using the INFORMATION_SCHEMA views in Sql Server 2005 & 2008 to obtain metadata
I'm using fluentnhibernate on SQL Server 2008. I have to objects Staff public class
When i use foreign keys in the entity framework the foreign key object is

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.