SQLviews
SQLviews
SQL Views
SQL view is a virtual table that is constructed from other
tables or views
It has no data of its own, but obtains data from tables or
other views
It only has a definition
1
CREATE VIEW Command
CREATE VIEW command:
CREATE VIEW view_name
AS
select_statement
2
Uses for SQL Views
Security: hide columns and rows
Display results of computations
Hide complicated SQL syntax
Provide a level of isolation between actual
data and the user’s view of data
three-tier architecture
Assign different processing permissions to
different views on same table
Kroenke, Database Processing 5
3
Display results of computations
Faculty (EmpID, LName, FName, Department,
AreaCode, LocalPhone)
Create a view to display 2 columns:
Name = Fname LName
Phone = (AreaCode) LocalPhone
SELECT, INSERT, UPDATE, DELETE?
4
Provide a level of isolation between
actual data and application
CREATE VIEW CustomerV AS
SELECT *
FROM Customers
Applications use CustomerV
Can change the underlying table without
changing the application
ALTER VIEW CustomerV AS
SELECT *
FROM New_Customers
Kroenke, Database Processing 9
Updating Views
CREATE VIEW CustomerV AS
SELECT *
FROM Customers
SELECT, INSERT, DELETE, UPDATE?
5
Updateable Views
Views based on a single table
No computed columns
All non-null columns present in view
Virtual table
It only has a definition
Data is computed at run-time from base tables
All views can be used in SELECT
Some views can be used in INSERT, DELETE,
UPDATE