Sample Query Based on Customers/Orders Scenario

To describe the logical processing phases in detail, I’ll walk you through a sample query. First run the code in Example 1-2 to create the Customers and Orders tables and populate them with sample data. Table 1-1 and Table 1-2 show the contents of Customers and Orders.

Example 1-2. Data definition language (DDL) and sample data for Customers and Orders

SET NOCOUNT ON; USE tempdb; GO IF OBJECT_ID('dbo.Orders') IS NOT NULL DROP TABLE dbo.Orders; GO IF OBJECT_ID('dbo.Customers') IS NOT NULL DROP TABLE dbo.Customers; GO CREATE TABLE dbo.Customers ( customerid CHAR(5) NOT NULL PRIMARY KEY, city VARCHAR(10) NOT NULL ); INSERT INTO dbo.Customers(customerid, city) VALUES('FISSA', 'Madrid'); INSERT INTO dbo.Customers(customerid, ...

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