Summary

Views are nothing more than stored T-SQL SELECT queries. There's no magic in a view. You can save any valid SELECT statement as a view, including subqueries, complex joins, and aggregate functions.

Views are great for simplifying a complex schema and presenting a more useful picture of the data for power users writing ad hoc queries and reports. Views can simplify complex aggregate queries and hide nasty joins. Any well-planned abstraction layer should include views. Be careful not to push the view too far. Don't expect to sort data in a view, and don't make views the pillar of the front-end application or website. However, for those who detest views, a view is infinitely better than an ad hoc SQL statement that directly hits a table without any abstraction layer.

The previous chapters have discussed retrieving data using the powerful SELECT statement. Views store the SELECT statement for ad hoc queries. The next chapter continues the discussion of SELECT, extending its power by adding data modification verbs.

Get Microsoft SQL Server 2012 Bible 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.