1

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?

alexey
  • 8,360
  • 14
  • 70
  • 102

1 Answers1

1

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

Pரதீப்
  • 91,748
  • 19
  • 131
  • 172
  • Edition should be Enterprise or Developer. – Bogdan Sahlean May 24 '16 at 17:26
  • Another option: SERVERPROPERTY('EngineEdition') = 3 /* Enterprise, Developer */ OR SERVERPROPERTY('EngineEdition') = 5 /* SQL Azure */. – alexey May 25 '16 at 08:38
  • 3
    If you run this script against SQL Express it still drops 'Online index operations can only be performed in Enterprise edition of SQL Server.' – alexey May 25 '16 at 08:38