title: How to create nonclustered index with online if available
body: <p>I'm adding a new index to a SQL Azure database as recommended by the query insights blade in the Azure portal, which uses the <code>ONLINE=ON</code> flag. The SQL looks something like this:</p>
  
  <pre><code>CREATE NONCLUSTERED INDEX [IX_MyIndex] ON 
         [Customers].[Activities] ([CustomerId]) 
     INCLUDE ([AccessBitmask], [ActivityCode], [DetailsJson], 
         [OrderId], [OperationGuid], [PropertiesJson], [TimeStamp]) 
     WITH (ONLINE = ON)"
  </code></pre>
  
  <p>However, we also need to add this same index to our local development databases, which are just <code>localdb</code> instances that don't support the <code>ONLINE=ON</code> option, resulting in the following error.</p>
  
  <pre><code>Online index operations can only be performed in Enterprise edition of SQL Server.
  </code></pre>
  
  <p>My question is - is there a way to write this SQL index creation statement that will use <code>ONLINE=ON</code> <em>if available</em>, but still succeed on databases that don't support it?</p>