Skip to content

Commit fbc68d6

Browse files
authored
Merge pull request #3587 from goranschwarz/dev
When your lazy and do not want to fill in all parameters... for: @DatabaseName, @SchemaName, @TableName
2 parents ad03442 + 9bac874 commit fbc68d6

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

sp_BlitzIndex.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ IF OBJECT_ID('dbo.sp_BlitzIndex') IS NULL
1313
GO
1414

1515
ALTER PROCEDURE dbo.sp_BlitzIndex
16+
@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' */
1617
@DatabaseName NVARCHAR(128) = NULL, /*Defaults to current DB if not specified*/
1718
@SchemaName NVARCHAR(128) = NULL, /*Requires table_name as well.*/
1819
@TableName NVARCHAR(128) = NULL, /*Requires schema_name as well.*/
@@ -132,6 +133,11 @@ DECLARE @PartitionCount INT;
132133
DECLARE @OptimizeForSequentialKey BIT = 0;
133134
DECLARE @StringToExecute NVARCHAR(MAX);
134135

136+
/* If user was lazy and just used @ObjectName with a fully qualified table name, then lets parse out the various parts */
137+
SET @DatabaseName = COALESCE(@DatabaseName, PARSENAME(@ObjectName, 3)) /* 3 = Database name */
138+
SET @SchemaName = COALESCE(@SchemaName, PARSENAME(@ObjectName, 2)) /* 2 = Schema name */
139+
SET @TableName = COALESCE(@TableName, PARSENAME(@ObjectName, 1)) /* 1 = Table name */
140+
135141

136142
/* Let's get @SortOrder set to lower case here for comparisons later */
137143
SET @SortOrder = REPLACE(LOWER(@SortOrder), N' ', N'_');

0 commit comments

Comments
 (0)