17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

10<br />

Views<br />

Up to this point, we’ve been dealing with base objects — objects that have some level of substance<br />

of their own. In this chapter, we’re going to go virtual (well, mostly anyway), and take a look at<br />

views.<br />

Views have a tendency to be used either too much, or not enough — rarely just right. When we’re<br />

done with this chapter, you should be able to use views to:<br />

❑ Reduce apparent database complexity for end users<br />

❑ Prevent sensitive columns from being selected, while still affording access to other important<br />

data<br />

❑ Add additional indexing to your database to speed query performance — even when<br />

you’re not using the view the index is based on<br />

A view is, at its core, really nothing more than a stored query. What’s great is that you can mix and<br />

match your data from base tables (or other views) to create what will, in most respects, function<br />

just like another base table. You can create a simple query that selects from only one table and<br />

leaves some columns out, or you can create a complex query that joins several tables and makes<br />

them appear as one.<br />

Simple V iews<br />

The syntax for a view, in its most basic form, is a combination of a couple of things we’ve already<br />

seen in the book — the basic CREATE statement that we saw back in Chapter 5, plus a SELECT<br />

statement like we’ve used over and over again:<br />

CREATE VIEW <br />

AS<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!