How to set Azure SQL to rebuild indexes automatically? : <p>In on premise SQL databases, it is normal to have a maintenance plan for rebuilding the indexes once in a while, when it is not being used that much.</p>

<p>How can I set it up in Azure SQL DB?</p>

<p>P.S: I tried it before, but since I couldn't find any options for that, I thought maybe they are doing it automatically until I've read <a href="https://blogs.msdn.microsoft.com/dilkushp/2013/07/27/fragmentation-in-sql-azure/" rel="noreferrer">this post</a> and tried:</p>

<pre><code>SELECT
 DB_NAME() AS DBName
 ,OBJECT_NAME(ps.object_id) AS TableName
 ,i.name AS IndexName
 ,ips.index_type_desc
 ,ips.avg_fragmentation_in_percent
 FROM sys.dm_db_partition_stats ps
 INNER JOIN sys.indexes i
 ON ps.object_id = i.object_id
 AND ps.index_id = i.index_id
 CROSS APPLY sys.dm_db_index_physical_stats(DB_ID(), ps.object_id, ps.index_id, null, 'LIMITED') ips
 ORDER BY ps.object_id, ps.index_id
</code></pre>

<p>And found out that I have indexes that need maintaining
<a href="https://i.stack.imgur.com/S2SIq.png" rel="noreferrer"><img src="https://i.stack.imgur.com/S2SIq.png" alt="enter image description here"></a></p>
