I'm using Ola Hallengren's maintenance scripts and I wanted to see if I could create 2 tables so that it logs integrity checks and index optimizations to different tables.
Sql-server – Index / Check DB Script question
dbcc-checkdbindexola-hallengrensql serversql server 2014
Related Question
- Sql-server – FillFactor: IndexOptimize script by Ola Hallengren
- Sql-server – Excluding Read only databases using Ola Hallengren script
- Sql-server – Long running index rebuild
- Sql-server – Amazon RDS Ola Hallengren
- Sql-server – Why is the DB size increasing when rebuildling an index using sort in tempDB in SQL Server
- Sql-server – Schedule suggestion and index rebuild / database integrity progress for Ola Hallengren’s Maintenance Script
Best Answer
Logging info to different tables is not possible without rewriting parts of Ola's solution and creating new objects.
By default, you can log the output to the
dbo.CommandLog
table by using@LogToTable = 'Y'
You can then query the recent outputs for the integrity checks with this command:
You can then change the filter to check the index rebuilds / reorgs by changing the filter to
WHERE CommandType = 'ALTER_INDEX'
.If you really want to change the tables, you could create a copy of the
dbo.CommandLog
table and createdbo.CommandLogIndex
for example.Afterwards you have to create a new procedure, a copy of the
dbo.CommandExecute
procedure to use thedbo.CommandLogIndex
table. I use Replace All (ALT + A
) in SSMS to change the procedure calls.As a last step, you could create a copy of the procedure
dbo.IndexOptimize
with the name[dbo].[IndexOptimizeLogToTable]
and change thedbo.CommandExecute
procedure calls todbo.CommandExecuteIndex
.Afterwards you run the procedure with
@logtotable='Y'
And you should see the results in the new
dbo.CommandLogIndex
table.