在触发器中调用 aspnet_Delete_User SP
我在学生表中有一个触发器,当我删除学生时,它会从其他表中删除相关记录。我想通过在触发器中调用 aspnet_delete_user 存储过程来删除学生的会员资格数据。但这仅在我删除一名学生时有效。如果我在一个查询中删除多个学生,它就不起作用。
如何调用这个SP进行多行操作触发器?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许是这样的:
此处查看更多信息 和 此处
Maybe something like this:
See more information here and here
您必须使用游标或构建动态 SQL 字符串(它使用游标而无需说明)。或者,您可以从存储过程中复制逻辑,看看是否可以将其定制为基于集合的 - 我还没有查看该过程,所以我不确定这是否可行、实用甚至可能,但是这是我在向触发器添加游标或动态 SQL 之前尝试做的第一件事。
对于游标,类似这样的东西(我猜你将 GUID 或其他东西传递给过程,但我不知道):
动态 SQL,相同的假设:
但是,预先包含丢失的信息更有用。不要假设每个使用 SQL Server 的人都知道 aspnet_delete_user 的作用。
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.