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

The Archive Base Latest Questions

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

Suppose I have a table called Companies that has a DepartmentID column. There’s also

  • 0

Suppose I have a table called Companies that has a DepartmentID column. There’s also a Departaments table that has as EmployeeID column. Of course I have an Employee table as well. The problem is that I want to delete a company, so first i have to delete all the employees for every departament and then all the departaments in the company. Cascade Delete is not an option, therefore i wish to use nested transactions. I’m new to SQL so I would appreciate your help.

  • 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. 2026-05-10T14:45:29+00:00Added an answer on May 10, 2026 at 2:45 pm

    I’m not sure why you need nested transactions here. You only need one actual transaction:

    BEGIN TRAN  DELETE FROM Employee     FROM Employee     INNER JOIN Department ON Employee.DepartmentID = Department.DepartmentID     INNER JOIN Company ON Department.CompanyID = Company.CompanyID     WHERE Company.CompanyID = @CompanyID  DELETE FROM Department     FROM Department     INNER JOIN Company ON Department.CompanyID = Company.CompanyID     WHERE Company.CompanyID = @CompanyID  DELETE FROM Company     WHERE Company.CompanyID = @CompanyID  COMMIT TRAN 

    Note the double FROM, that is not a typo, it’s the correct SQL syntax for performing a JOIN in a DELETE.

    Each statement is atomic, either the entire DELETE will succeed or fail, which isn’t that important in this case because the entire batch will either succeed or fail.

    BTW- I think you had your relationships backwards. The Department would not have an EmployeeID, the Employee would have a DepartmentID.

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

Sidebar

Ask A Question

Stats

  • Questions 69k
  • Answers 69k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Up to a sign, the determinant of an n-by-n matrix… May 11, 2026 at 12:44 pm
  • added an answer You should probably ask this in the DotNetNuke forums: http://www.dotnetnuke.com/tabid/795/default.aspx.… May 11, 2026 at 12:44 pm
  • added an answer You may have the Perl scripting engine embedded in a… May 11, 2026 at 12:44 pm

Related Questions

Suppose I have a table called Companies that has a DepartmentID column. There's also
Suppose I have a table . Now, I'm interested in Getting Useful Data Easily.
Suppose I have a database table with two fields, foo and bar. Neither of
Suppose I have a tags table with two columns: tagid and contentid . Each
Suppose I have a database table that has a timedate column of the last
I wish to find all rows in a table where one column is a
I have seen this issue twice now and want to see what a best
What is the SQL command to copy a table from one database to another
I have a table called Area, that stores areas in a hierarchical manner. There

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.