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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:35:18+00:00 2026-05-30T05:35:18+00:00

I have a trigger in students table that deletes related records from other tables

  • 0

I have a trigger in students table that deletes related records from other tables when i delete a student. I want to delete student’s membership data by calling aspnet_delete_user stored procedure in the trigger . but this works just if I delete one student . and if I remover multiple students in one query it doesn’t work .

How to call this SP for multi-row operation trigger ?

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

    You’d have to use a cursor or build a dynamic SQL string (which uses a cursor without saying so). Alternatively, you could copy the logic from the stored procedure and see if you can tailor it to become set-based – I haven’t looked at the procedure, so I’m not sure if this is feasible, practical or even possible, but it’s the first thing I try to do before adding cursors or dynamic SQL to a trigger.

    For a cursor, something like this (I’m guessing you pass a GUID or something to the procedure, but I have no idea):

    CREATE TRIGGER dbo.StudentAfterDelete
    ON dbo.Students
    AFTER DELETE
    AS
    BEGIN
      SET NOCOUNT ON;
    
      DECLARE @MemberID UNIQUEIDENTIFIER;
    
      DECLARE c CURSOR LOCAL STATIC FORWARD_ONLY READ_ONLY
        FOR SELECT MemberID FROM deleted;
    
      OPEN c;
    
      FETCH NEXT FROM c INTO @MemberID;
    
      WHILE @@FETCH_STATUS <> -1
      BEGIN
        EXEC dbo.aspnet_delete_user @MemberID;
    
        FETCH NEXT FROM c INTO @MemberID;
      END
    
      CLOSE c;
      DEALLOCATE c;
    END
    GO
    

    Dynamic SQL, same assumptions:

    CREATE TRIGGER dbo.StudentAfterDelete
    ON dbo.Students
    AFTER DELETE
    AS
    BEGIN
      SET NOCOUNT ON;
    
      DECLARE @sql NVARCHAR(MAX) = N'';
    
      SELECT @sql += 'EXEC dbo.aspnet_delete_user ''' 
        + CONVERT(VARCHAR(36), MemberID) + ''';' FROM deleted;
    
      EXEC sp_executesql @sql;
    END
    GO
    

    However including the missing information up front is more useful. Don’t assume that everyone who works with SQL Server has any clue what aspnet_delete_user does.

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

Sidebar

Related Questions

We have a trigger that creates audit records for a table and joins the
I have a trigger that check data before insert to another table IF NOT
I have a trigger that stores changes made in a separate table when a
I have a trigger for insert/update/delete. That is working fine. Also, I need the
is is possible in postgres to have a trigger on CREATE TABLE that will
I have a trigger on a table that should never be disabled. It performs
I have two tables as students and certificates, I need to delete the certificates
I have one table 'Students' and one table 'Applications'. Each student can apply for
I have a trigger that sets a datetime field in a table row when
I have a trigger which is sending data from a table to another table

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.