Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

What are triggers in Microsoft SQL Server? Kindly Explain with examples.

user-image
Question ajoutée par Salman Khalid , Application & API Support Engineer , Adamjee Insurance Co. Ltd.
Date de publication: 2016/12/28
shakeel mir
par shakeel mir , Senior Software Developer , Rawat-Al-Makan

A trigger is a special kind of stored procedure that automatically executes when an event occurs in the database server. DML triggers execute when a user tries to modify data through a data manipulation language (DML) event. DML events are INSERT, UPDATE, or DELETE statements on a table or view. These triggers fire when any valid event is fired, regardless of whether or not any table rows are affected.

Two type of Trigger

INSTEAD OF and AFTER,

An INSTEAD OF trigger is the one that is usually associated with a view, and runs on an UPDATE action placed on that view.

An AFTER trigger fires after a modification action has occurred.

Syntax of a Trigger CREATE TRIGGER name ON table   [WITH ENCRYPTION]   [FOR/AFTER/INSTEAD OF]   [INSERT, UPDATE, DELETE]   [NOT FOR REPLICATION]ASBEGIN--SQL statements...END

 

Sample Example   CREATE TRIGGER [TRIGGER_ALTER_COUNT] ON [dbo].[tblTriggerExample] FOR INSERT, UPDATEASBEGINEND

haytham Hamdy
par haytham Hamdy , Developer , SAP

A special kind of stored procedure which executed automatically after/instead of a specific event occur in the database

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?