Created
March 26, 2024 13:22
-
-
Save NJohnson9402/4f81ecc77fac73743a0060247ade0f4a to your computer and use it in GitHub Desktop.
Create Index with Online if Enterprise Ed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @ver nvarchar(MAX), @cmd nvarchar(MAX); | |
SELECT @ver = @@VERSION; | |
SET @cmd = N'CREATE INDEX IX_TableName_Description ON dbo.TableName | |
(Column1, Column2) | |
INCLUDE (Column3, Column4) | |
'; | |
IF (NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'IX_TableName_Description' | |
AND object_id = OBJECT_ID('dbo.TableName'))) | |
BEGIN | |
IF (@ver LIKE '%standard edition%') | |
SET @cmd += N'WITH (DATA_COMPRESSION=PAGE)'; | |
ELSE | |
SET @cmd += N'WITH (ONLINE=ON, DATA_COMPRESSION=PAGE)'; | |
EXEC sp_executesql @cmd; | |
END; | |
--rollback: | |
--DROP INDEX IX_TableName_Description ON dbo.TableName; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment