0% found this document useful (0 votes)
36 views

Triggers Views

Triggers in SQL Server are special stored procedures that automatically execute in response to events like data modification. A trigger contains an event that activates it, an optional condition, and an action - a procedure that runs when the trigger is activated and its condition is met. Triggers ensure that a control procedure runs before or after a statement on a table to maintain data integrity.

Uploaded by

Afshan Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Triggers Views

Triggers in SQL Server are special stored procedures that automatically execute in response to events like data modification. A trigger contains an event that activates it, an optional condition, and an action - a procedure that runs when the trigger is activated and its condition is met. Triggers ensure that a control procedure runs before or after a statement on a table to maintain data integrity.

Uploaded by

Afshan Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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
A trigger has three parts:
• Event
Change to the database that activates the trigger
• Condition
Query or test that is run when the trigger is activated
• Action
Procedure that is executed when the trigger is activated and its condition is true
 Triggers can be executed once per modified record or once per activating statement.
 The good reason to use DML SQL triggers is the case when you want to assure that a
certain control shall be performed before or after the defined statement on the defined
table.

VIEWS
Views in SQL are kind of virtual tables. A view also has rows and columns as they are in a real table in the
database. We can create a view by selecting fields from one or more tables present in the database. A
View can either have all the rows of a table or specific rows based on certain condition

We can create View using CREATE VIEW statement. A View can be created from a single table or multiple
tables

Syntax:

CREATE VIEW view_name AS


SELECT column1, column2.....
FROM table_name
WHERE condition;
view_name: Name for the View
table_name: Name of the table
condition: Condition to select rows

E.G

In this example we will create a View named DetailsView from the table StudentDetails. Query:
CREATE VIEW DetailsView AS
SELECT NAME, ADDRESS
FROM StudentDetails
WHERE S_ID < 5;

You might also like