Professional Documents
Culture Documents
SQL Server 2008 Trainning
SQL Server 2008 Trainning
Yudhi Kurniawan
Topics
Views
Stored
Procedures
User Defined Functions
Triggers
Views
T-SQL View
Views
CREATE VIEW [owner.]view_name
[(column_name [, column_name]...)]
[WITH ENCRYPTION]
AS select_statement [WITH CHECK OPTION]
Alter Views
Drop Views
Rename View
Indexed Views
Because indexed views are more complex to maintain than indexes on base
tables, you should use them only when the improved speed in retrieving the
results outweighs the increased overhead of data modifications.
Set the ANSI_NULLS option to ON when you create the tables referenced by the
view
Set the ANSI_NULLS and QUOTED_IDENTIFIER options to ON prior to creating the
view
The view must only reference base tables, not any other views
Base tables referenced by the view must be in the same database as the view and
must have the same owner
Create the view and any user-defined functions referenced in the view with the
SCHEMABINDING option. This means that the underlying tables or other database
objects cannot be altered or dropped as long as the view or function exists.
Reference all table names and user-defined functions with two-part names onlyfor
example, "dbo.Customers" for the Customers table.
Any functions used by the view must be deterministic, meaning that the function
must always return the same result anytime it's called with the same set of input
values.
A unique clustered index must be created before any other indexes can be created
on the view.
Additional disk space will be required to hold the data defined by the indexed view.
Examples
Drop Procedure
EXECUTE procedure_name
Parameterized Procedures
Try..Catch Block
Implements error handling for Transact-SQL that is similar to the exception
handling in the programming languages. A group of Transact-SQL statements
can be enclosed in a TRY block. If an error occurs in the TRY block, control is
passed to another group of statements that is enclosed in a CATCH block.
TRYCATCH constructs can be nested. Either a TRY block or a CATCH block can
contain nested TRYCATCH constructs.
In the scope of a CATCH block, the following system functions can be used
to obtain information about the error that caused the CATCH block to be
executed:
ERROR_NUMBER() returns the number of the error.
ERROR_LINE() returns the line number inside the routine that caused
the error.
Scalar UDFs
Limitations of UDFs
AFTER Triggers
INSTEAD OF Triggers
INSTEAD OF triggers facilitates updating Views.
A view or table can have only one INSTEAD OF trigger for each INSERT,
UPDATE and DELETE events
Why Triggers?
More on Triggers
THANK
YOU