Can we call a Trigger in store procedure? [Resolved]

Posted by Muhsinathk under Sql Server on 6/13/2012 | Points: 10 | Views : 19338 | Status : [Member] | Replies : 14
Hi,

Can we call a Trigger in store procedure?




Responses

Posted by: Muhsinathk on: 9/13/2012 [Member] Bronze | Points: 50

Up
0
Down

Resolved
A trigger is a pl/sql block structure which is fired when a DML statements like Insert, Delete, Update is executed on a database table. A trigger is triggered automatically when an associated DML statement is executed.

Syntax of Triggers

The Syntax for creating a trigger is:

CREATE [OR REPLACE ] TRIGGER trigger_name

{BEFORE | AFTER | INSTEAD OF }

{INSERT [OR] | UPDATE [OR] | DELETE}

[OF col_name]

ON table_name

[REFERENCING OLD AS o NEW AS n]

[FOR EACH ROW]

WHEN (condition)

BEGIN

--- sql statements

END;

SQL Server 2000 has many types of triggers:

1. After Trigger
2. Multiple After Triggers
3.Instead Of Triggers
4. Mixing Triggers Type

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shoyebaziz123 on: 6/13/2012 [Member] Starter | Points: 25

Up
0
Down
Trigger can't be called , it is automatically executed when we insert,update or delete a table row

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gemamgall on: 6/27/2012 [Member] Starter | Points: 25

Up
0
Down
Triggers are event based statements so they cannot be called explicitly by user in any means.

Thanks and Regards,

Vinay Gandhi
www.quadtechindia.com

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 6/28/2012 [Member] Starter | Points: 25

Up
0
Down
No, You can't Call Trigger Manually,

it is fired when any update made in Table who has trigger

Ajay
ajaypatelfromsanthal.blogspot.in

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bhupentiwari on: 6/28/2012 [Member] Starter | Points: 25

Up
0
Down
No you can not call. it is program which is automatically fired when inset/delete/update is executed

Thanks n Regards
Bhupendra Tiwari

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 6/28/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
No, you can not call trigger in proc. it will automatically fired when an event fired like INSERT / DELETE / UPDATE

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 9/13/2012 [Member] Bronze | Points: 25

Up
0
Down
Differences between storedprocedures and triggers
1. When you create a trigger you have to identify event and action of your trigger but when you create s.p you don't identify event and action

2.Trigger is run automatically if the event is occured but s.p don't run automatically but you have to run it manually

3. Within a trigger you can call specific s.p but within a sp you cannot call atrigger

4.Trigger execute implicitly whereas store procedure execute via procedure call from another block.

5.We can call a stored procedure from front end (.asp files, .aspx files, .ascx files etc.) but we can't call a trigger from these files.

6. Stored procedure can take the input parameters, but we can't pass the parameters as an input to a trigger.


Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/13/2012 [Member] Starter | Points: 25

Up
0
Down
No,We can't call triggers in storedprocedure

Thanks & Regards
Hari

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 9/14/2012 [Member] Bronze | Points: 25

Up
0
Down
No,We cannot call a trigger in a storedprocedure.
Within a trigger you can call specific storedprocedure but within a storedprocedure you cannot call atrigger

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 9/14/2012 [Member] Bronze | Points: 25

Up
0
Down
Please Mark as Answer if it helpful to you..That helps others who search the same...

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/14/2012 [Member] Starter | Points: 25

Up
0
Down
Please Mark as Answer if u satisfied for this answer

Thanks & Regards
Hari

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amrutag on: 12/9/2015 [Member] Starter | Points: 25

Up
0
Down
I want to add data in two table simultaneously. Can i use insert statement inside the after insert trigger?

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bhupentiwari on: 12/9/2015 [Member] Starter | Points: 25

Up
0
Down
No

Thanks n Regards
Bhupendra Tiwari

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajeshatkiit on: 12/18/2015 [Member] Starter | Points: 25

Up
0
Down
Triggers are event based. It is getting called when insertion, deletion or update happen to the table. Trigger cannot be called from store proc.

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response