Chapter 14. Projecting Data Through Views

IN THIS CHAPTER

  • Planning views wisely

  • Creating views with Management Studio or DDL

  • Updating through views

  • Performance and views

  • Nesting views

  • Security through views

  • Synonyms

A view is the saved text of a 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 can't 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 views don't store any data. Like any other SQL query, views merely refer to the data stored in tables.

With this in mind, it's important 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?

While there are several opinions on the use of views, ranging from total abstinence to overuse, the Information Architecture Principle (from Chapter 2, "Smart Database Design") 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 ease of writing ad hoc queries, and not as a central part of a production application, here are some ideas for building ...

Get Microsoft® SQL Server® 2008 Bible now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.