Skip to content

Commit

Permalink
Merge pull request #3587 from goranschwarz/dev
Browse files Browse the repository at this point in the history
When your lazy and do not want to fill in all parameters... for: @DatabaseName, @SchemaName, @TableName
  • Loading branch information
BrentOzar authored Oct 23, 2024
2 parents ad03442 + 9bac874 commit fbc68d6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sp_BlitzIndex.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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.*/
Expand Down Expand Up @@ -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'_');
Expand Down

0 comments on commit fbc68d6

Please sign in to comment.