Skip to content

Commit b1366da

Browse files
Update sp_IndexCleanup.sql
1 parent 55ad36e commit b1366da

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

sp_IndexCleanup/sp_IndexCleanup.sql

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ALTER PROCEDURE
1717
dbo.sp_IndexCleanup
1818
(
1919
@database_name sysname = NULL, /*focus on a single database*/
20-
@schema_name sysname = NULL, /*use when focusing on a single table, does not filter to a single schema*/
20+
@schema_name sysname = NULL, /*use when focusing on a single table, or to a single schema with no table name*/
2121
@table_name sysname = NULL, /*use when focusing on a single table*/
2222
@min_reads bigint = 0, /*only look at indexes with a minimum number of reads*/
2323
@min_writes bigint = 0, /*only look at indexes with a minimum number of writes*/
@@ -104,8 +104,8 @@ BEGIN TRY
104104
CASE
105105
ap.name
106106
WHEN N'@database_name' THEN 'the name of the database you wish to analyze'
107-
WHEN N'@schema_name' THEN 'the schema name to filter indexes by - limits analysis to tables in the specified schema'
108-
WHEN N'@table_name' THEN 'the table name to filter indexes by'
107+
WHEN N'@schema_name' THEN 'limits analysis to tables in the specified schema when used without @table_name'
108+
WHEN N'@table_name' THEN 'the table name to filter indexes by, requires @schema_name if not dbo'
109109
WHEN N'@min_reads' THEN 'minimum number of reads for an index to be considered used'
110110
WHEN N'@min_writes' THEN 'minimum number of writes for an index to be considered used'
111111
WHEN N'@min_size_gb' THEN 'minimum size in GB for an index to be analyzed'
@@ -1016,9 +1016,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10161016
N'.' +
10171017
QUOTENAME(@table_name);
10181018

1019-
SELECT
1020-
@object_id =
1021-
OBJECT_ID(@full_object_name);
1019+
SET @object_id = OBJECT_ID(@full_object_name);
10221020

10231021
IF @object_id IS NULL
10241022
BEGIN
@@ -1134,18 +1132,19 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11341132
RAISERROR('adding object_id filter', 0, 0) WITH NOWAIT;
11351133
END;
11361134

1137-
SELECT @sql += N'
1135+
SET @sql += N'
11381136
AND t.object_id = @object_id';
11391137
END;
11401138

1141-
IF @schema_name IS NOT NULL AND @object_id IS NULL
1139+
IF @schema_name IS NOT NULL
1140+
AND @object_id IS NULL
11421141
BEGIN
11431142
IF @debug = 1
11441143
BEGIN
11451144
RAISERROR('adding schema_name filter', 0, 0) WITH NOWAIT;
11461145
END;
11471146

1148-
SELECT @sql += N'
1147+
SET @sql += N'
11491148
AND s.name = @schema_name';
11501149
END;
11511150

0 commit comments

Comments
 (0)