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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:55:28+00:00 2026-06-01T13:55:28+00:00

Imagine a database that tracks payments between customers. Say I’ve got a Customer table:

  • 0

Imagine a database that tracks payments between customers.

Say I’ve got a Customer table:

Customer 
----------
CustomerID
Name

and a Transaction table

Transaction
------------
BuyerID
SellerID
Amount

Where BuyerID and SellerID are both Foreign Key references to the CustomerID column of the Customer table.

In my current (analogous) situation, the Transaction table is large (500 Million Rows), even though the Customer table is small (2000 rows). Deleting a row from the Customer table, however, takes a very long time, because the database has to scan the Transaction table to see whether the Customer has any referencing Transactions (In fact, it has to do it twice – one to check for BuyerID and one for SellerID). The Transaction table is not Indexed on either BuyerID or SellerID (The real table is indexed on a combination of Buyer, Seller, and a few other columns)

I know I can drop all the foreign key constraints, delete the rows, and then re-add the constraints. Will that be any faster than just doing the DELETE FROM with the foreign keys enabled? Are there any other ways to speed up the delete operation that I’m missing.

  • 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-06-01T13:55:30+00:00Added an answer on June 1, 2026 at 1:55 pm

    You should index BuyerID and SellerID in your Transaction table…

    For a further explanation as to why you should be indexing your foreign keys, read Kimberly Tripp’s excellent article on the subject.

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

Sidebar

Related Questions

Imagine the following database: Table 'companies' has fields id, name and flagship_product_id. Table 'products'
Imagine a database table that looks like this: create table [dbo].[user] ( id int
Imagine you have a database table that stores a list of people. You want
What is the best way to track changes in a database table? Imagine you
Imagine the following (simplified) database layout: We have many holiday records that relate to
I have a table in my SQL database that stores an AccountID and an
imagine a database setup, where x customers can make y orders. normally all customers
I am designing a database with the code igniter datamapper. Imagine that I have
Please imagine this small database... Diagram removed dead ImageShack link - volunteer database diagram
Imagine the following problem: You have a database containing about 20,000 texts in a

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.