SQL Triggers and Stored Procedures

 

Trigger:

  • A trigger is a stored procedure in database which automatically invokes whenever a special event in the database occurs.
  • Trigger are nothing but logic, which execute before insert, update and delete.
  • They help us to executes preprocessing logic.


Types of Triggers:

1. AFTER Trigger :

  • AFTER triggers are fired after the SQL server finishes execution of actions like insert, update and delete fired.  
  • Executes after the data modification.

2. INSTEAD OF Trigger :

  • INSTEAD OF triggers are fired before the SQL server starts execution of actions like insert, update and delete gets fired. 
  • Executes prior to data modification. 


Creating Triggers  :

 1. Select New Trigger from table :

 2. Create trigger :

 2. Execute trigger :

 


Stored Procedures :

  • Stored Procedures is a block code which we can re-use.
  • Stored procedures are pre-compiled, their syntax and plans are already checked, so it increases the performance.


Inline SQL :

  • Inline query is a query within the from clause.
  • SQL plan, Syntax check are executed each and everytime when we fire a query.


Creating Stored Procedure : 

1) Select Programmability => Stored Procedures => New => Stored Procedures  : 


2) Create Procedure :

3) Execute Stored Procedures :


Types of Stored Procedure :

1) System Defined Stored Procedure : 

  • These stored procedures are already defined in SQL Server. 
  • Eg. sp_rename

2) Extended Procedure : 

  • These procedures provide an interface to external programs for various maintenance activities.
  • Eg. xp_logininfo

3) User-Defined Stored Procedure : 

  • These procedures are created by the user for own actions.

4) CLR Stored Procedure : 

  • These procedure are special type of procedure that is based on the CLR (Common Language Runtime) in .net framework.



Thank You!!!


For more understanding watch below video :

Comments

Popular posts from this blog

Day 3 : JavaScript

SQL Concepts-1

ASP .NET Session Management