Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

271


CHAPTER


11


Projecting Data Through Views


IN THIS CHAPTER


Planning Views Wisely

Creating Views with Management Studio or DDL

Updating Through Views

Considering Performance and Views

Using Nesting Views

Exploring Security through Views

Learning Synonyms

A


view is the saved text of a T-SQL SELECT statement that may be referenced as a data source
within a query, similar to how a subquery can be used as a data source—no more, no less. A
view cannot be executed by itself; it must be used within a query.

Views are sometimes described as “virtual tables.” This isn’t an accurate description because all views
do not store any data. Views that are indexed are materialized and actually store data. If they are
not indexed, they are like any other SQL query; views merely refer to the data stored in tables.

With this in mind, you need to fully understand how views work, the pros and cons of using views,
and the best place to use views within your project architecture.

Why Use Views? .................................................................................................


Although several opinions exist for the use of views, ranging from total abstinence to overuse, the
Information Architecture Principle (from Chapter 2, “Data Architecture”) serves as a guide for their
most appropriate use. The principle states that “information ... must be ... made readily available
in a usable format for daily operations and analysis by individuals, groups, and processes ...”

Presenting data in a more useable format is precisely what views do best.

Based on the premise that views are best used to increase data integrity and for ease of writing
ad hoc queries, and not as a central part of a production application, following are some ideas for
building ad hoc query views:

c11.indd 271c11.indd 271 7/30/2012 4:41:01 PM7/30/2012 4:41:01 PM


http://www.it-ebooks.info
Free download pdf