Wednesday, April 11, 2012

How to call Stored Procedure from Trigger in MS SQL


Another interesting Interview question “Can we call Stored procedure form Trigger in MS SQL”? What will be your answer YES or NO? Answer should always be “YES”.

You can call Stored Procedure from trigger. In this article we will go through a simple After Insert trigger as an example.

create trigger trg_Ins_CustTrigger on Customer
After Insert 
Declare @Name as varchar(100)
Declare @Address as varchar(100)
select @Name=Name, @Address=Address from inserted
exec CustDet @Name, @Address

I believe above code is self explanatory as the table and field names I have used is a clear English text.

If you have any question please post it in comment section.

1 comment:

Gitu said...

It is very useful...