In this blog we are going to understand Sql trigger and stored procedure.
Trigger:
- Trigger are nothing but logic, which execute before insert. update and delete.
- Triggers are a special kind of stored procedure.
- It executes implicitly.
- When an event occur trigger is automatically executed.
- types of Trigger:
1.Instead of Trigger:
- Instead of trigger will be fired instead insert,update and delete operations on a table.
2.After Trigger:
- After trigger fired after insert,update and deleter operations on a table.
Syntax of Creating Trigger:-
CREATE TRIGGER trigger_name
ON table_name
AFTER {[INSERT],[UPDATE],[DELETE]}
AS
BEGIN
{sql_statements}
END
ON table_name
AFTER {[INSERT],[UPDATE],[DELETE]}
AS
BEGIN
{sql_statements}
END
How to create the Trigger:
Example:
CREATE TRIGGER
See the trigger are created:
RESULT OF TRIGGER
STORED PROCEDURE:
- A stored procedure is nothing but it is block of code which we can code reusable.
- The stored procedure increase performance because they are pre-compiler, there plan are precompile and there syntax are checked at front.
- Syntax:
CREATE PROCEDURE proc_name
AS
Begin
{sql_statement}
End
AS
Begin
{sql_statement}
End
How to create the stored procedure:
right click on programmability-->stored procedure.
See the stored procedure are created:
No comments:
Post a Comment