Friday, June 18, 2021

Trigger and Stored procedure SQL -part 7

 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

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.
CREATE PROCEDURE proc_name
AS
Begin
{sql_statement}
End
How to create the stored procedure:
right click on programmability-->stored procedure.



Example:
                                                    
See the stored procedure are created:
                                            
To execute a stored procedure, we use the EXECUTE or EXEC the statement followed by the name of the stored procedure:
                                   

For more understanding watch below video :

      
Thank You!!!

No comments:

Post a Comment

Function in SQL -part 8

  In this blog we are going to understand  Sql function.   FUNCTION: A function is a database object in SQL Server. It accepts only input pa...