触发器存储程序 [英] Trigger & Store procedure

查看:78
本文介绍了触发器存储程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Freinds,

我为Clerk表编写了一个存储过程,我想在运行存储过程时发生一次触发。我说如果clk_Id想要删除另一个表中的存在时给我一条消息但是我的代码没有运行。

你能帮帮我吗?



Hi Freinds,
I've written a store procedure for Clerk table and i want when i run the store procedure one trigger happen. I said if the clk_Id when want to delete existence in another table give me a message but my code don't run.
Could you help me?

CREATE Procedure [dbo].[Clerk_Delete]

@clk_Id		int

As
Begin
    Begin Try
        Begin Tran a
            Delete From Clerk
            Where clk_Id = @clk_Id
            Commit Tran a;
    End Try
    Begin Catch
        Rollback Tran a;
    End Catch
End










CREATE Trigger [dbo].[Clerk_Insert_Trigger] on [dbo].[Clerk]
For delete
As
--declare @a int;
--select @a = Clerk.clk_Id from Clerk

If  exists (Select HokmeKargozini.clk_Id  from HokmeKargozini )
Begin
  print 'You don''t remove this clerk ';
  ROLLBACK tran a;
End
else
Begin
    print 'It''s removed ';
End

推荐答案

请先阅读我的评论。我不确定你想要达到什么目的,但我只能猜测你是想从SP调用触发器。



看看这里:

存储过程和触发器 [ ^ ]

存储过程和触发器中的回滚和提交 [ ^ ]

如何使用CONTEXT_INFO审核或绕过TRIGGER执行() [ ^ ]

SQL SERVER - 如何使用而不是触发器 - 来宾帖子作者:Vikas Munjal - Koenig Solutions [ ^ ]

SQL SERVER - 缺点(问题) )触发器 [ ^ ]
Please, read my comment first. I'm not sure what are you trying to achieve, but i can only guess that you're trying to call trigger from SP.

Have a look here:
Stored Procedures and Triggers[^]
Rollbacks and Commits in Stored Procedures and Triggers[^]
How to Audit or Bypass TRIGGER Execution Using CONTEXT_INFO() [^]
SQL SERVER – How to Use Instead of Trigger – Guest Post by Vikas Munjal – Koenig Solutions[^]
SQL SERVER – Disadvantages (Problems) of Triggers[^]


这篇关于触发器存储程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆