DECLARE @return_value int

EXEC @return_value = [dbo].[IndexOptimize]
@Databases = N'DatabaseName', @UpdateStatistics = N'ALL', @LogToTable = N'Y', @MaxDOP=1

SELECT 'Return Value' = @return_value

GO
  •  BrentOzarULTD First Responder Kit. GitHub , BrentOzar
    • sp_Blitz
    • sp_BlitzFrist
    • sp_BlitzCache
    • sp_BlitzIndex
    • sp_BlitzQueryStore
    • sp_BlitzRS
    • sp_BlitzTrace
    • sp_BlitzWho
    • sp_DatabaseRestore
EXEC dbo.sp_WhoIsActive @get_plans = 1, 
    @get_locks= 1, 
    @get_additional_info = 1, 
    @get_transaction_info = 1,
    @output_column_list = '[dd hh:mm:ss.mss][session_id][host_name][login_name][database_name][sql_text][blocking_session_id]
    [program_name][CPU][reads][writes][physical_reads][used_memory][wait_info][status][tempdb_allocations][tempdb_current]
    [open_tran_count][tran_log_writes][tran_start_time][login_time][start_time][percent_complete][query_plan][locks][additional_info][request_id]'