Link Search Menu Expand Document

sp_sizeoptimiser

sp_sizeoptimiser bag logo

Purpose

A stored procedure that recommends space saving and corrective data type measures based on SQL Server database schemas. Great for quickly assessing databases that may have non-optimal data types. Especially useful for SQL Server Express to help stay under the 10GB file size limitations.

Storage is cheap, but smaller is faster!

Arguments

ParameterTypeOutputDescription
@IndexNumThresholdSMALLINTnoNumber of indexes to classify a table as having too many indexes on it. Default value is 10.
@IncludeDatabasesSIZEOPTIMISERTABLETYPEnoWhich databases to run the script on in the form of a user defined table type. If not supplied, all accessible user databases are targeted. Cannot be used in conjunction with @ExcludeDatabases.
@ExcludeDatabasesSIZEOPTIMISERTABLETYPEnoWhich databases to exclude in the form of a user defined table type. Cannot be used in conjunction with @IncludeDatabases.
@IncludeSysDatabasesBITnoWhether or not to include system databases in the script’s analysis. Default is 0.
@IncludeSSRSDatabasesBITnoWhether or not to include SQL Server Reporting Services databases in the script’s analysis. Default is 0.
@VerboseBITnoWhether or not to print additional information during the script run. Default is 0.
@IsExpressBITnoUsed for unit testing purposes only.
@SqlMajorVersionTINYINTnoUsed for unit testing purposes only.
@SqlMinorVersionSMALLINTnoUsed for unit testing purposes only.

Usage

Basic example:

DECLARE @includeDatabases SizeOptimiserTableType;

INSERT INTO @includeDatabases ([database_name])
VALUES (N'WideWorldImporters');

EXEC [dbo].[sp_sizeoptimiser] @IncludeDatabases = @includeDatabases;
GO

Output

For WorldWideImporters:

sp_sizeoptimiser output