SQL Query History

It’s not necessary to manually save every query that you run or those that are executed on a regular basis, such as monthly tasks, in a separate document. The SQL Query History feature captures and stores essential details about your executed SQL commands over a given time span, allowing for easy access. This functionality enables users to review, modify, and look up past queries executed on the database. Additionally, it provides insights into who ran each query and when, alongside other pertinent details.

The SQL Query History is particularly useful in scenarios where an examination of past actions is required, such as investigating specific cases, reviewing backup logs, or retrieving queries after an SQL Server malfunction.

The Query History is organized into two main sections:

SQL Query History grid: A tabular representation of the query history.

Preview pane: An area for viewing detailed query information.

The columns in the SQL Query History grid include:

Status: Reflects the success or failure of the query execution. Query Text: The text of SQL query that was executed. Database: The name of the database where the query ran. Size (in bytes): The memory footprint of the query. Executed On: The exact time and date the query was run. Duration: The time it took for the query to execute. File: The name of the file containing the SQL statement. Server: The server on which the query was executed. User: The individual who initiated the query execution.

To open the SQL Query History window, point to Other Windows in the View menu, and then select SQL Query History.

The window looks in the following way:

History Execution Window

Setting Up SQL Query History behavior

To set up behavior of SQL Query History:

1. On the Tools menu, click Options. The Options dialog opens.

2. Navigate to Environment, Documents, SQL Query History.

3. To enable storing query SQL Query History, select the checkbox next to the Store executed queries within option, and set the number of days to store executed queries.

4. Optionally, modify the path to store the SQL Query History database, maximum script size to store, and timeframe for default output of SQL Query History.

The default period to store the executed queries is 60 days. The maximum interval you can set is 365 days. After the specified period has ended, the history is automatically deleted. You can also upload the file with the history data by copying it from the folder on your computer to the required place. The default folder to store is C:\Users\Username\AppData\Roaming\Devart\dbForge Studio for SQL Server\ExecutedQueries.

The file cannot be later viewed from the dbForge tool because the old data will be auto-deleted.

Execution Options

Filtering SQL Query History

To quickly find the required query, you can:

  • Type the search string into the Search box and specify query execution time frame.
  • Use sorting, grouping, and filtering.

Filtering History

Editing Query

To edit an executed SQL query, right-click it in the SQL Query History list and select To New SQL Window. This will open the query in a new SQL document, where you make any necessary modifications to its text.

Alternatively, simply double-click the required query in the SQL Query History list.

Editing Query

Download dbForge Studio for SQL Server and try it absolutely free for 30 days!

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All Features

All features

Get acquainted with the rich features and capabilities of the Studio in less than 5 minutes.
Request a demo

Request a demo

If you consider employing the Studio for your business, request a demo to see it in action.
Ready to start using dbForge Studio for SQL Server?