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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:31:32+00:00 2026-05-22T02:31:32+00:00

Sometimes I have to delete two records on different tables. How could I execute

  • 0

Sometimes I have to delete two records on different tables. How could I execute the query in a way where if one fails the other one will not execute and the other way around. In other words, that the database gets updated only if both queries are successful otherwise don’t make any changes. That way if I get any errors I know nothing has changed. I am executing this query in C# as:

//qDelete is a string containing the query
// connection - SqlConnection 

SqlCommand cmd = new SqlCommand(qDelete, connection);
try
{
    var t = cmd.ExecuteNonQuery();
    MessageBox.Show("Query succesfully executed \n \n" + "\n\n" + t + " records successfully deleted");
}
catch
{
    //do something here to avoid having any changes to the database          
}

That’s is great. My sDelete string gets build dynamically and the only things that I am missing is to place the statements in the right order. I have figured that I have to delete first the records from the dependent table or table that has constrains then from the other table. How could I see which table is dependent on the other will help me build this query. I could do something like sort all the strings and place the ones that contains the table that has no constrain first then place the other ones. How can I find out which table depends on the other to make this even better?

  • 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-22T02:31:33+00:00Added an answer on May 22, 2026 at 2:31 am

    You want to use a Transaction to gather the two updates together and let them either both succeed or neither happen. That link includes a sample that does two inserts, but you can easily adapt it for two deletes.

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

Sidebar

Related Questions

I sometimes have difficulties with other people who wish to solve a problem when
In our application we sometimes have to make minor GUI modifications for different customers:
I use AIR HTML component, and I need to delete cookies sometimes. I have
I sometimes have issues with the incremental rebuild on visual C++ (2003 currently ).
In my database application I sometimes have to deal with null strings in the
My situation: I have several components, which sometimes have changes to them, and are
In the Visual Studio code editor, I sometimes have an extraneous mark on the
Sometimes I have to work on code that moves the computer clock forward. In
I'm using C and sometimes I have to handle paths like C:\Whatever C:\Whatever\ C:\Whatever\Somefile
As everyone knows, sometimes developers have to document stuff. Or capture some stuff for

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.