You are on page 1of 3

Creating and

Modifying Views
View Concepts
SELECT statement designed to act as a table
Uses
Simplify complex table structure
Enhance security
Potentially increase performance
View Concepts
Limitations on creating views
Maximum 1,024 columns
No ORDER BY statement unless using TOP
Single query returning a single table
Cannot use SELECT ... INTO
Cannot reference a temporary table or table variable
Limitations on modifying view data
Cannot modify data in multiple tables
Cannot modify if using an aggregate function
View Limitations
Use two-part naming
Dont join views
Practice good query writing
Dont use SELECT *
Only return required data
View Best Practices
View Syntax
-- Create or Alter view
{ CREATE | ALTER } VIEW <name>
[WITH <options>]
AS
-- SELECT statement
[ WITH CHECK OPTION ]

-- Drop view
DROP VIEW <name>;
View Syntax
ENCRYPTION
Encrypts the definition, preventing all users from accessing the
script
Issues
Nobody can access it
Easily cracked

SCHEMABINDING
Underlying tables cannot be modified in a way that would impact
the view
View Options
VIEW_METADATA
Enables external APIs to browse metadata

CHECK OPTION
Specified at the end
Prevents modifications that would cause data to leave the view
View Options

You might also like