SQL Views
SQL Views
- Simplify data retrieval from complex queries
- Hiding the underlying table structure
- Controlling access to data for different users
Data Modification
- Modifying records through a view must meet all rules/constraints on the table(s) the view is based on.
- An
INSERTorUPDATEfrom a view cannot affect more than one table in the view. - You cannot
DELETEfrom a view that is based on more than one table. - If the
SELECTstatement containsGROUP BY,DISTINCT,TOP, orUNION, you cannot modify data in that view.
Syntax
CREATE VIEW ViewName
AS
SELECT …
Retrieving the definition:
SP_HELPTEXT ViewName
Altering or Dropping Views
ALTER VIEW ViewName
AS
SELECT …
DROP VIEW ViewName