A-Z of Mircrosoft SQL

Main Page Introduction SSMS Acronym's used in SQL SQL Commands SQL Functions SQL Store Procedures SQL Views SQL Triggers SQL Operators SQL - Adding Comments SQL Alias SQL Joins SQL - Building Basic Scripts SQL - Execution Plan Questions or Suggestions
H1B Jobs- Visual Reports

SQL Examples

Arithmetic Operators Comparision Operators Logical Operators Bitwise Operators String Functions Date Functions Numeric Functions


SQL Triggers

In SQL Server, triggers are database objects, actually, a special kind of stored procedure, which “reacts” to certain actions we make in the database. The main idea behind triggers is that they always perform an action in case some event happens. If we’re talking about DML triggers, these changes shall be changes in our data. Let’s examine a few interesting situations:

1)In case you perform an insert in the call table, you want to update that related customer has 1 more call (in that case, we should have integer attribute in the customer table)

2)When you complete a call (update call.end_time attribute value) you want to increase the counter of calls performed by that employee during that day (again, we should have such attribute in the employee table)

3)When you try to delete an employee, you want to check if it has related calls. If so, you’ll prevent that delete and raise a custom exception

There are THREE types of TRIGGERS

DML (data manipulation language) triggers – These triggers react to DML commands.

INSERT

UPDATE

DELETE

DDL (data definition language) triggers – These triggers react to DDL commands

CREATE

ALTER

DROP

Logon triggers – This type reacts to LOGON events

Next Stop: SQL Operators