III.8.1. Tying Information Together with Views

A view allows you to access specific columns easily from one or more tables with a simple query.

Views provide two significant benefits:

  • Simplify data retrieval: Although the query creating the view can be quite complex, the query that retrieves the data from the view is very simple. It looks like this:

    SELECT *
    FROM ViewName
  • Maintain security: If permission is granted on the view, permissions to the underlying table(s) aren't needed to retrieve data from the view. At the same time, permission to the underlying table can be expressly denied.

A view doesn't actually hold any data; instead, it's a virtual table. Each time data is requested from a view, it actually retrieves the data from the underlying tables.

Figure 8-1 shows an Employees table. The table includes personal data, such as name and phone number. It also shows data that is much more private, such as Social Security number and salary.

Figure III.8-1. A Contact table including salary and SSN data.

If you want someone to have access to a phone listing of employees, you could create a query for them and allow them to run the query whenever they want to access the data.

The query would look like this:

SELECT FirstName, LastName, Phone
FROM Employees

Even for a simple requirement, such as a phone listing, the query can look quite intimidating to someone unfamiliar with T-SQL. ...

Get Microsoft® SQL Server™ 2008 All-In-One Desk Reference For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.