ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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

user-image
تم إضافة السؤال من قبل Salman Khalid , Application & API Support Engineer , Adamjee Insurance Co. Ltd.
تاريخ النشر: 2016/12/28
shakeel mir
من قبل 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
من قبل haytham Hamdy , Developer , SAP

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

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟