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 ?
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):
Dynamic SQL, same assumptions:
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.