开发者

Is it possible to pass a parameter to trigger in SQL Server database?

Ta开发者_开发问答ble can have trigger on insert/delete/update. Trigger will be fired internally by DB engine.

Is it possible to pass a parameter to trigger in SQL Server database like a stored procedure?


Indirectly via CONTEXT_INFO(). See Using Session Context Information. The fact that your trigger needs extra state is always a code smell.


Nope.

See: http://www.eggheadcafe.com/community/aspnet/13/10006230/pass-values-in-trigger.aspx


You can kludge it. Create a table specifically designed to hold the parameter information, then place data into the the parameter table before performing the operation that will initiate the trigger. Code the trigger to read from the parameter table.

That was the carrot, here is the stick:

  1. This will complicate your triggers. You will need to account for the potential of missing paramters, and you will have to provide cleanup for the parameters.
  2. You are creating a dependency with this technique, so it will only work with processes that are coded to use this parameter passing technique. So if your data is modified by more than just your application, this won't work.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜