Sample Data for This Chapter
Throughout the chapter, I will use the Performance database and its tables in my examples. Run the code in Example 3-1 to create the database and its tables, and populate them with sample data. Note that it will take a few minutes for the code to finish.
Example 3-1. Creation script for sample database and tables
SET NOCOUNT ON; USE master; GO IF DB_ID('Performance') IS NULL CREATE DATABASE Performance; GO USE Performance; GO -- Creating and Populating the Nums Auxiliary Table IF OBJECT_ID('dbo.Nums') IS NOT NULL DROP TABLE dbo.Nums; GO CREATE TABLE dbo.Nums(n INT NOT NULL PRIMARY KEY); DECLARE @max AS INT, @rc AS INT; SET @max = 1000000; SET @rc = 1; INSERT INTO Nums VALUES(1); WHILE @rc * 2 <= @max BEGIN INSERT INTO ...
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.