You manage an Azure SQL Database that supports a critical application. You need to automate the process of rebuilding indexes that have fragmentation above 30% on a weekly basis. The solution must use built-in database features and minimize performance impact. What should you do?
Trap 1: Create a SQL Agent job that runs ALTER INDEX REBUILD on all indexes…
SQL Agent is not available in Azure SQL Database (single database); it is only supported in Azure SQL Managed Instance. Therefore, you cannot create a SQL Agent job in a single database environment, regardless of the T-SQL logic. Even if SQL Agent were present, rebuilding all indexes with fragmentation >30% using ALTER INDEX REBUILD could cause blocking and resource contention; but the primary showstopper is that the service itself is unavailable. Azure SQL Database's native scheduling alternative is Elastic Jobs (now called Elastic Database Jobs), which runs T-SQL scripts on a schedule across one or more databases.
Trap 2: Use Azure Automation to run a PowerShell script that checks…
Azure Automation is an external orchestration service, not a built-in database feature. Running a PowerShell script in an Azure Automation runbook requires storing and managing credentials outside the database, adding operational overhead and security complexity. The requirement explicitly asks for built-in database features, and Azure Automation does not integrate natively within the Azure SQL Database engine for scheduled index maintenance. Additionally, while a PowerShell script could connect to the database and execute index rebuilds, it relies on external scheduling and network connectivity, making it less reliable and not a platform-native solution.
Trap 3: Enable automatic tuning and set the 'Force plan' and 'Create index'…
Incorrect. Automatic tuning in Azure SQL Database includes 'Create index' and 'Force plan' options, but these do not rebuild indexes with high fragmentation. 'Create index' adds new indexes, and 'Force plan' stabilizes query plans. Neither addresses index fragmentation.
- A
Create a SQL Agent job that runs ALTER INDEX REBUILD on all indexes with fragmentation >30%.
Why wrong: SQL Agent is not available in Azure SQL Database (single database); it is only supported in Azure SQL Managed Instance. Therefore, you cannot create a SQL Agent job in a single database environment, regardless of the T-SQL logic. Even if SQL Agent were present, rebuilding all indexes with fragmentation >30% using ALTER INDEX REBUILD could cause blocking and resource contention; but the primary showstopper is that the service itself is unavailable. Azure SQL Database's native scheduling alternative is Elastic Jobs (now called Elastic Database Jobs), which runs T-SQL scripts on a schedule across one or more databases.
- B
Use Azure Automation to run a PowerShell script that checks fragmentation and rebuilds indexes.
Why wrong: Azure Automation is an external orchestration service, not a built-in database feature. Running a PowerShell script in an Azure Automation runbook requires storing and managing credentials outside the database, adding operational overhead and security complexity. The requirement explicitly asks for built-in database features, and Azure Automation does not integrate natively within the Azure SQL Database engine for scheduled index maintenance. Additionally, while a PowerShell script could connect to the database and execute index rebuilds, it relies on external scheduling and network connectivity, making it less reliable and not a platform-native solution.
- C
Enable automatic tuning and set the 'Force plan' and 'Create index' options.
Why wrong: Incorrect. Automatic tuning in Azure SQL Database includes 'Create index' and 'Force plan' options, but these do not rebuild indexes with high fragmentation. 'Create index' adds new indexes, and 'Force plan' stabilizes query plans. Neither addresses index fragmentation.
- D
Schedule a weekly job using elastic jobs to reorganize all indexes.
Correct. Elastic Jobs are a built-in feature of Azure SQL Database that allow you to schedule T-SQL scripts. You can create a job that queries sys.dm_db_index_physical_stats and rebuilds indexes with fragmentation >30% on a weekly schedule, minimizing performance impact by running during off-peak times.