§ A view is a virtual table.
§ Database views are created
using the CREATE VIEW statement.
§ Views can be created from a
single table, multiple tables, or another view.
§ When we update a view it will update underline base table.
CREATEVIEWview_nameAS
SELECT column1, column2.....
FROMtable_name
WHERE [condition]
Example:
CREATEVIEW CUSTOMERS_VIEW AS
SELECT name, age
FROM CUSTOMERS
SELECT*FROM CUSTOMERS_VIEW
Advantages
§
Reduce complexity of database schema.
§
Mechanism to implement row and column level security.
§
Represent aggregate data and hide detailed data.
Limitations
§ Cannot pass parameter to view.
§ Rules and default cannot be associated with the view.
§ Order by clause is invalid in a view unless TOP or XML is also
specified.
§ Cannot be created on the bases of temporary tables.
Indexed
View
§ Create unique clustered index on the view.
§ As we create index on a view it will become capable of storing data.
§ A view that is to be indexed has
to be created with schema binding. This means that once the indexed view is
created, the underlying tables cannot be altered in any way that would
materially affect the indexed view unless the view is first altered or dropped.
CREATEVIEWMyViewWITHSCHEMABINDINGAS
SELECT ID, Duration
FROMdbo.OAGTable
WHEREDurationinMin> 300
GO
Comments
Post a Comment