Modular Approach

Views can be used to develop solutions in a modular way. You solve each step of the problem with a query, and define a view based on that query. This process simplifies the solution by allowing you to focus on a single step at a time.

I’ll demonstrate a modular approach through an example. First, run the code in Example 5-1 to create and populate the Sales table:

Example 5-1. Creating and populating the Sales table

SET NOCOUNT ON; USE tempdb; GO IF OBJECT_ID('dbo.Sales') IS NOT NULL DROP TABLE dbo.Sales; GO CREATE TABLE dbo.Sales ( mnth DATETIME NOT NULL PRIMARY KEY, qty INT NOT NULL ); INSERT INTO dbo.Sales(mnth, qty) VALUES('20041201', 100); INSERT INTO dbo.Sales(mnth, qty) VALUES('20050101', 110); INSERT INTO dbo.Sales(mnth, qty) ...

Get Inside Microsoft® SQL Server™ 2005 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.