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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:12:12+00:00 2026-05-19T06:12:12+00:00

I have a situation where I have a Header and a Detail table. The

  • 0

I have a situation where I have a Header and a Detail table. The Detail table has a foreign key relationship to the Header table with Cascade delete.

When the detail records are deleted I need to update other tables using a trigger. The problem I am having is that I need to pull some information from the Header table as well as the Detail table for the deleted records. If I delete the Detail records and then the Header record the trigger appears to run fine. However, if I delete the Header record, which in turn deletes the Detail records due to the cascading delete, then when the trigger executes the Header record is already deleted and I can’t access the information I need from it.

I am rather new to triggers, so I’m wondering if there is something I just don’t know and how I accomplish this.

Here is my code:

ALTER TRIGGER [Detail_Delete]
   ON [Detail]
   AFTER DELETE
AS 
BEGIN
 SET NOCOUNT ON;

 DECLARE @Table UpdateTableType

 -- Here is where the problem lies.
 -- No records are found here because the Header record isn't found.
 INSERT @Table
 (HeaderID, UserID)
 SELECT d.HeaderID, h.UserID
 FROM deleted d
 JOIN Header h ON h.HeaderID = d.HeaderID

 EXECUTE sp_UpdateSummary
  @Table = @Table
END
  • 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-19T06:12:13+00:00Added an answer on May 19, 2026 at 6:12 am

    I wouldn’t use a cascade delete because as you’ve seen, the deleted parent data isn’t available

    A stored procedure is ideal for this. If not for whatever reason, you can use a BEFORE trigger on the Header table to do the Detail and other deletes (and of course the Header table)

    ALTER TRIGGER [Header_Delete]
       ON [Header]
       INSTEAD OF DELETE
    AS 
    BEGIN
     SET NOCOUNT ON;
    
     DECLARE @Table UpdateTableType
    
     -- DELETED has data, even though Header has not yet been touched
     INSERT @Table
     (HeaderID, UserID)
     SELECT d.HeaderID, d.UserID
     FROM deleted
    
     DELETE Detail WHERE ... (using @Table)
    
     DELETE Other WHERE ... (using @Table)
    
     DELETE Header WHERE ... (using @Table)
    
     EXECUTE sp_UpdateSummary
      @Table = @Table ...
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation where I need to increase the space between a table
I have situation where I need to change the order of the columns/adding new
Pseudo-situation: have a class (let's say BackgroundMagic ), and it has Start() and Stop()
I have this situation: $(#button).toggle(function(){ $(#window).animate({top:'0%'},1000); },function(){ $(#window).animate({top:'-100%'},1000); }); but I need change it
I have a situation when there's a table and you can add a new
I need help with C programming. I have the following situation: struct Product {
I have a, probably unique situation in which I need to use a single
I have a situation. I have some functions in a header file that are
I can't understand such situation: I have a site template and in header there
I have a situation where I build a view with a table and another

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.