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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:00:23+00:00 2026-05-21T05:00:23+00:00

I want to know the use of foreign key in SQL Server as I

  • 0

I want to know the use of foreign key in SQL Server as I had a debate with one of my colleagues.

I have the opinion, when two tables are connected via a foreign key, when the records are deleted from the parent table then the same reference record from the child table should also get deleted.

Say for example I have two tables, Table1 and Table2. Table1 has one record with id = 1 and Table2 has two records with id = 1. Table2 is a child table and connected with Table1 via a foreign key. Now when I try to delete the id = 1 record from Table1 then id = 1 (2 records) should be deleted from Table2 at the same time.

He says that’s wrong. In case of a foreign key, I have to separately delete records from both the tables.

Who is correct?

  • 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-21T05:00:24+00:00Added an answer on May 21, 2026 at 5:00 am

    Both answers can be used and can work.

    Your colleague’s version puts more responsability on your application (or your DBA) doing the deletion: the app (or DBA) will have to check for child rows first and delete them, and then delete the parent row. This works, and doesn’t give you any unexpected surprises.

    If you put a ON DELETE CASCADE option on your foreign key constraint (which should be possible in just about any serious relational database system), then the behavior would be the way you describe it – that might make sense, from a business point of view (e.g. delete all order items for an order), but in other cases, it might totally make no sense at all (e.g. if you delete an order no. 1234, you typically don’t want to delete all the products the order items for that order will probably reference).

    So there are two scenarios – both make sense in certain scenarios, and not such much in others. It’s not a simple “either – or” / “right vs. wrong” question at all.

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

Sidebar

Related Questions

I currently have two joined tables in a SQL Server database, one with news
I Want to know which one is preferred while coding to use Static Methods
I want to know which one is stable, fast and easy to use?
Scenario I have 3 database tables. One is for Images and the other two
I have one table orders with a foreing key ProductID. I want to show
I have a table that has an autoincrement surrogate key. I want to use
I want to know what is the use of .properties file and where it
i want to know that when we want to use push notification service.From where
I want to use push notification in my app.i want to know that do
I want to know how and when can I use the exit() function like

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.