From 9bac87496715ad84ede69b5f9d295377cd59cd45 Mon Sep 17 00:00:00 2001 From: Goran Schwarz Date: Wed, 23 Oct 2024 23:08:30 +0200 Subject: [PATCH] When your lazy and do not want to fill in all parameters: @DatabaseName, @SchemaName and @TableName Now you can simply do: EXEC sp_BlitzIndex @ObjectName = 'schema.tablename' Or if you're really lazy do: EXEC sp_BlitzIndex 'schema.tablename' --- sp_BlitzIndex.sql | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sp_BlitzIndex.sql b/sp_BlitzIndex.sql index 32e5e70a..747e42cf 100644 --- a/sp_BlitzIndex.sql +++ b/sp_BlitzIndex.sql @@ -13,6 +13,7 @@ IF OBJECT_ID('dbo.sp_BlitzIndex') IS NULL GO ALTER PROCEDURE dbo.sp_BlitzIndex + @ObjectName NVARCHAR(386) = NULL, /* 'dbname.schema.table' -- if you are lazy and want to fill in @DatabaseName, @SchemaName and @TableName, and since it's the first parameter can simply do: sp_BlitzIndex 'sch.table' */ @DatabaseName NVARCHAR(128) = NULL, /*Defaults to current DB if not specified*/ @SchemaName NVARCHAR(128) = NULL, /*Requires table_name as well.*/ @TableName NVARCHAR(128) = NULL, /*Requires schema_name as well.*/ @@ -132,6 +133,11 @@ DECLARE @PartitionCount INT; DECLARE @OptimizeForSequentialKey BIT = 0; DECLARE @StringToExecute NVARCHAR(MAX); +/* If user was lazy and just used @ObjectName with a fully qualified table name, then lets parse out the various parts */ +SET @DatabaseName = COALESCE(@DatabaseName, PARSENAME(@ObjectName, 3)) /* 3 = Database name */ +SET @SchemaName = COALESCE(@SchemaName, PARSENAME(@ObjectName, 2)) /* 2 = Schema name */ +SET @TableName = COALESCE(@TableName, PARSENAME(@ObjectName, 1)) /* 1 = Table name */ + /* Let's get @SortOrder set to lower case here for comparisons later */ SET @SortOrder = REPLACE(LOWER(@SortOrder), N' ', N'_');