alexey
alexey

Reputation: 8480

Creating index in SQL Server with ONLINE = ON if supported

I'm creating an index in a SQL Server table with ONLINE = ON option:

CREATE INDEX IX_Name ON Users (Name) WITH ONLINE = ON

If this script is run on non-Enterprise SQL Server edition I get this error:

Online index operations can only be performed in Enterprise edition of SQL Server.

How to write a SQL script to use ONLINE = ON option on Enterprise editions and not to use it for non-supported editions?

Upvotes: 1

Views: 6209

Answers (1)

Pரதீப்
Pரதீப்

Reputation: 93704

Something like this should help

IF  SERVERPROPERTY ('edition') like '%Enterprise%Edition%'
BEGIN
CREATE INDEX IX_Name ON Users (Name) WITH ONLINE = ON
END

Also I think the login you are using should have permission to View Server State

Upvotes: 1

Related Questions