Technical Conventions
@Databases — Database Selection
Select databases using keywords, wildcards, and exclusions. The hyphen character (-) excludes databases, the percent character (%) is a wildcard, and the comma (,) combines operations. Defaults to USER_DATABASES when NULL.
| Value | Description |
|---|---|
USER_DATABASES | All user databases (default when NULL) |
SYSTEM_DATABASES | All system databases (master, msdb, model) |
ALL_DATABASES | All databases |
AVAILABILITY_GROUP_DATABASES | All databases in availability groups |
Db1 | The database Db1 |
Db1, Db2 | The databases Db1 and Db2 |
%pattern% | All databases matching the pattern |
USER_DATABASES, -Db1 | All user databases except Db1 |
USER_DATABASES, -%test% | All user databases excluding names matching %test% |
ALL_DATABASES, -%Db% | All databases that do not match the pattern |
USER_DATABASES, -AVAILABILITY_GROUP_DATABASES | All user databases that are not in availability groups |
All procs that accept @Databases use the shared function optimize.fn_GetDatabases for consistent parsing.
@RunnableUnder Parsing
Every proc that accepts @RunnableUnder uses the same parsing pattern:
DECLARE @ThresholdStd DECIMAL(10,2) = NULL;
DECLARE @ThresholdEnt DECIMAL(10,2) = NULL;
DECLARE @ActiveThreshold DECIMAL(10,2) = NULL;
IF @RunnableUnder IS NOT NULL AND LTRIM(RTRIM(@RunnableUnder)) <> ''
BEGIN
IF @RunnableUnder LIKE '%,%e'
BEGIN
SET @ThresholdStd = TRY_CAST(LEFT(@RunnableUnder, CHARINDEX(',', @RunnableUnder) - 1) AS DECIMAL(10,2));
SET @ThresholdEnt = TRY_CAST(SUBSTRING(@RunnableUnder, CHARINDEX(',', @RunnableUnder) + 1,
LEN(@RunnableUnder) - CHARINDEX(',', @RunnableUnder) - 1) AS DECIMAL(10,2));
END
ELSE
BEGIN
SET @ThresholdStd = TRY_CAST(@RunnableUnder AS DECIMAL(10,2));
SET @ThresholdEnt = @ThresholdStd;
END
END
SET @ActiveThreshold = CASE WHEN @IsEnterprise = 1 THEN @ThresholdEnt ELSE @ThresholdStd END;
@LinkedServer Post-Processing
When @LinkedServer = 1, the orchestrator's combined output is post-processed line-by-line:
USE [db] / GO— captured, removed (injected inside EXEC)- Comments — pass through as-is
CREATE INDEX+ continuations +DROP INDEX— collected into oneEXEC('USE [db]; ...') AT [server]; GOUPDATE DBA_Utilities...— own EXEC AT/* */blocks (from @RunnableUnder) — wrap around the EXEC
Enterprise Detection
Used for: WITH (ONLINE = ON) on index operations, and the Enterprise threshold in @RunnableUnder.
IF CAST(SERVERPROPERTY('Edition') AS NVARCHAR(500)) LIKE '%Enterprise%'
OR CAST(SERVERPROPERTY('Edition') AS NVARCHAR(500)) LIKE '%Developer%'
SET @IsEnterprise = 1;