Objectives: Understanding, Creating & Managing Views
Objectives: Understanding, Creating & Managing Views
• UNDERSTANDING,
CREATING & MANAGING VIEWS
VIEWS
TABLE T1
Col 1 Col 2 Col 3 Col 4 Col 5 Col 6
VIEWS
CREATE VIEW vwDepartment
AS
SELECT [DepartmentID]
,[Name]
,[GroupName]
CREATE
,[ModifiedDate]
FROM [dbo].[Department]
GO
SELECT [DepartmentID]
,[Name]
EXECUTE
,[GroupName]
,[ModifiedDate]
FROM vwDepartment
GO
VIEWS
Advantages:
• Security
Users can be restricted direct access to a table and only allowed
to access a subset of data via views.
Ex: Users are only allowed to access customer name, phone, email via
a view but restricted from accessing the bank account and other
sensitive information.
VIEWS
Advantages (Cont...):
• Simplicity
A relational database may have many tables with complex
relationships, e.g., one-to-one and one-to-many that make it
difficult to navigate.
However, one can simplify the complex queries with joins and
conditions using a set of views.
VIEWS
Advantages (Cont...):
• Consistency
Sometimes, there is a need to write complex formulae or logic
in every query.
Disadvantages:
• Performance
Complex, multi-table views may take considerable time due to
translation which actually are referred to the underlying source
tables.
VIEWS
Disadvantages (Cont...):
• Update Restrictions
Multi-table views are often required to be restricted to
read-only.
VIEWS
Limitations:
AS
SELECT [DepartmentID]
,[Name]
,[GroupName]
,[ModifiedDate]
FROM [dbo].[Department]
GO
From SQL Server 2016, Microsoft added “CREATE OR ALTER” for creating/modifying
procedural object definition
VIEWS
DROPPING
More…
VIEWS
Data Modification: