Professional Documents
Culture Documents
Triggers Views
Triggers Views
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:
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;