How to Find out the Time Points When Someone Checks Database Consistency in SQL Server

There are several database consistency checker commands. It is recommended that we should rarely execute FREEPROCCACHE in production environments. In this article, we will learn how to identify when database consistency checker commands were executed in your production environment.

Using SSMS

Messages available in the SQL Server Error logs can be an information or an error. At the time of an issue, this error log will help you to investigate quickly.

To identify when was the DBCC FREEPROCCACHE was executed on your SQL server, follow the steps mentioned below:

Step 1: Connect to your SQL Server database engine using SQL Server management studio.

Step 2: From the object explorer, expand the folder “Management” and then navigate to the subfolder “SQL Server Logs”. The number of archive log files available per SQL instance can vary from 6 to 99. By default, you can see 7 log files under “SQL Server logs” and it would include 1 current log file and 6 archive log files.

Step 3: To read data from a log file, double click and open it. A new window will open and in this window, you will see data on the left and checkboxes on the right which allows the selection of other archive log files.

 Step 4: You can now search for “DBCC FREEPROCCACHE” to reach the row that has Date, Source, and Message that was logged at the time of execution of DBCC FREEPROCCACHE. As an alternative, you could filter multiple logs. The entry would look like the following message:

SQL Server has encountered 1 occurrence(s) of cache store flush for the ‘Bound Trees’ cache store (part of plan cache) due to ‘DBCC FREEPROCCACHE’ or ‘DBCC FREESYSTEMCACHE’ operations.

Using T-SQL

After connecting to your SQL Server database engine using SQL Server management studio, open a new query window and execute the query below:

 EXEC sp_readerrorlog 0, 1, 'DBCC FREEPROCCACHE' 

0 in the above query indicates that the current log file would be scanned for entries during the execution of DBCC FREEPROCCACHE

1 indicates that the log file used is SQL Server Error log file

Let us test it.

Before testing this, let us first recycle the log file so it is easy for us to view the content. To recycle the SQL Server Error log file, execute this command from a new query window.


And then execute this command:


Now, if you check the SQL Server error log file, you will see entries as shown in the screenshot:

SQL Server Error Log

This script will recycle your SQL Server error log every day at 12:00 AM.

 USE [msdb]
SELECT @ReturnCode = 0
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode =  msdb.dbo.sp_add_job @job_name=N'Daily_Cycle_log',
        @description=N'No description available.',
        @category_name=N'[Uncategorized (Local)]',
        @owner_login_name=N'ECPL\naveenv', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'S1',
        @os_run_priority=0, @subsystem=N'TSQL',
        @command=N'Exec sp_cycle_errorlog',
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'S1',
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
GOTO EndSave

A regular usage of DBCC commands would help you to avoid SQL Server corruption. So make sure you have a maintenance plan to check the integrity of your databases.

Author Introduction:

Neil Varley is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including Outlook repair and excel recovery software products. For more information visit

Leave a Reply

Your email address will not be published. Required fields are marked *