May 2006
Intermediate to advanced
536 pages
15h 13m
English
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) ...