Skip to content

Commit

Permalink
Merge pull request #286 from pmasl/master
Browse files Browse the repository at this point in the history
Update view_IndexCreation.sql
  • Loading branch information
bluefooted authored Nov 30, 2022
2 parents bdaaa63 + 2d33f5a commit 7e5a320
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Index-Creation/view_IndexCreation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
-- 2009-05-21 Changed index scoring method; Disregards indexes with [Score] < 100000 and [User_Hits_on_Missing_Index] < 99;
-- 2013-03-21 Changed database loop method;
-- 2013-11-10 Added search for redundant indexes in missing indexes;
-- 2022-11-22 Fixed issue with included column index generation

SET NOCOUNT ON;
SET QUOTED_IDENTIFIER ON;
Expand Down Expand Up @@ -245,7 +246,8 @@ BEGIN
CHAR(10) + 'USE ' + QUOTENAME(IC.DBName) + CHAR(10) + 'GO' + CHAR(10) + 'IF EXISTS (SELECT name FROM sysindexes WHERE name = N''' +
IC.[Ix_Name] + ''') DROP INDEX ' + IC.[Table] + '.' +
IC.[Ix_Name] + ';' + CHAR(10) + 'GO' + CHAR(10) + 'CREATE INDEX ' +
IC.[Ix_Name] + ' ON ' + IC.[Table] + ' (' + IC.[KeyCols] + CASE WHEN @editionCheck = 1 THEN ') WITH (ONLINE = ON);' ELSE ');' END + CHAR(10) + 'GO' + CHAR(10)
IC.[Ix_Name] + ' ON ' + IC.[Table] + ' (' + IC.[KeyCols] + ')' + CHAR(10) + 'INCLUDE (' + IC.[IncludedCols] + ')' +
CASE WHEN @editionCheck = 1 THEN ' WITH (ONLINE = ON);' ELSE ');' END + CHAR(10) + 'GO' + CHAR(10)
FROM #IndexCreation IC
WHERE IC.[IncludedCols] IS NOT NULL AND IC.[Score] >= 100000
ORDER BY IC.DBName, IC.[Table], IC.[Ix_Name]
Expand Down

0 comments on commit 7e5a320

Please sign in to comment.