View Dsil
View Dsil
View Dsil
Logically represents subsets of data from one or more tables A view is a DBO that consists of columns from one or more tables. It is a query stored as an object.
Advantages of VIEW
To restrict data access To make complex queries easy
Creating a View
CREATE VIEW View_Name [(Column List)] [with {ENCRYPTION |SCHEMABINDING | VIEW METADAT}] AS Select [WITH CHECK OPTION]
CREATE VIEW EMPV (Ename, Minsal, Maxsal, Avgsal) AS SELECT d.DeptName,MIN(e.salary), MAX(e.salary),AVG(e.salary) FROM employees e JOIN Departments d ON (e.DeptNo = d.DeptId) GROUP BY d.DeptName
Querying a View
Any attempt to change the department number for any row in the view fails because it violates the WITH CHECK OPTION constraint.
WITH Encryption
The WITH ENCRYPTION option encrypts the SELECT statement, thus enhancing the security of the database system. Software vendors who use SQL Server in the back end often encrypt their views or stored procedures in order to prevent tampering or reverse-engineering from clients or competitors. If you use encryption, be sure to save the original, unencrypted definition.
WITH SCHEMABINDING
The SCHEMABINDING clause binds the view to the schema of the underlying table. Creating a view with the SCHEMABINDING option locks the tables being referred by the view and prevents any changes that may change the table schema.
Drop View
You can remove a view without losing data because a view is based on underlying tables in the database. DROP VIEW view; DROP VIEW empvu80; ALTER VIEW "Alphabetical list of products" AS SELECT Statement
Indexed View
A view created with a unique clustered index is known as an Indexed View or Materialized View. Unlike views, an Indexed View exists on the disk like a table in which the clustered index is created. Once a clustered index is created you may create non-clustered indexes on the view CREATE VIEW vwOrderDetails WITH SCHEMABINDING AS SELECT OD.OrderID, OD.ProductID, P.ProductName , OD.UnitPrice , OD.Quantity, OD.Discount FROM dbo.Products P INNER JOIN dbo.[Order Details] OD ON P.ProductID = OD.ProductID GO SET QUOTED_IDENTIFIER ON SET ANSI_NULLS ON GO CREATE UNIQUE CLUSTERED INDEX [IDX_vwOrderDetails]