USE master
go

IF DATABASEPROPERTYEX('ChargeTestingResults', 'COLLATION') IS NOT NULL
	DROP DATABASE ChargeTestingResults
go

CREATE DATABASE ChargeTestingResults
ON PRIMARY 
	(NAME = N'ChargeTestingData', 
	FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL\Data\ChargeTestingResultsData.mdf', 
	SIZE = 20,
	FILEGROWTH = 10%,
	MAXSIZE = 100)
LOG ON 
	(NAME = N'ChargeTestingLog', 
	FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL\Data\ChargeTestingResultsLog.ldf', 
	SIZE = 4, 
	FILEGROWTH = 10%)
go

USE ChargeTestingResults
go

-- DROP TABLE dbo.TablesToProcess
-- DROP TABLE dbo.DeleteTestResults
-- DROP TABLE dbo.FragmentationResults

--------------------------------------------
-- Create a table to be used to run and 
-- capture all of the test results.
--------------------------------------------
CREATE TABLE dbo.TablesToProcess
(
	TableName				sysname		NOT NULL
)
go

INSERT dbo.TablesToProcess
	VALUES ('ChargeHeap')
INSERT dbo.TablesToProcess
	VALUES ('ChargeCLPKForDelete')
INSERT dbo.TablesToProcess
	VALUES ('ChargeCLDateForDelete')
INSERT dbo.TablesToProcess
	VALUES ('ChargeCLDateForDeleteWithCompPK')
INSERT dbo.TablesToProcess
	VALUES ('ChargeCLReallyBadForDelete')
INSERT dbo.TablesToProcess
	VALUES ('ChargeHeapWNCIndexes')
INSERT dbo.TablesToProcess
	VALUES ('ChargeCLPKForDeleteWNCIndexes')
INSERT dbo.TablesToProcess
	VALUES ('ChargeCLDateForDeleteWNCIndexes')
INSERT dbo.TablesToProcess
	VALUES ('ChargeCLDateForDeleteWithCompPKWNCIndexes')
INSERT dbo.TablesToProcess
	VALUES ('ChargeCLReallyBadForDeleteWNCIndexes')
go

CREATE TABLE dbo.DeleteTestResults
(
	TestRunID				tinyint		identity		NOT NULL,
	TestGroupName			varchar(20)	NOT NULL,
	TableName				sysname		NOT NULL,
	TestRunStartTime		datetime	NOT NULL,
	RowsDeleted				int			NOT NULL,
	DeleteTime				int			NOT NULL
)
go

CREATE TABLE dbo.FragmentationResults
(
	RowID					smallint		identity,
	TestRunID				tinyint			NULL,
	ObjectName				sysname,
	ObjectId				int,
	IndexName				sysname,
	IndexId					tinyint,
	Level					tinyint,
	Pages					int,
	Rows					bigint,
	MinimumRecordSize		smallint,
	MaximumRecordSize		smallint,
	AverageRecordSize		smallint,
	ForwardedRecords		bigint,
	Extents					int,
	ExtentSwitches			numeric(10,2),
	AverageFreeBytes		numeric(10,2),
	AveragePageDensity		numeric(10,2),
	ScanDensity				numeric(10,2),
	BestCount				int,
	ActualCount				int,
	LogicalFragmentation	numeric(10,2),
	ExtentFragmentation		numeric(10,2)
)
go