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 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 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:

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

Preview pane: An area for viewing detailed query information.

The columns in the Query History grid include:

  • Status: Reflects the success or failure of the query execution.

  • Query Text: The text of SQL query that was executed.

  • Size (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.

  • Database: The name of the database where the query ran.

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

The window looks in the following way:

History Execution Window

Set up the Query History behavior

To set up the behavior of Query History:

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

2. Navigate to Environment, Documents, Query History.

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

4. Optionally, modify the path to store the Query History database, and the maximum script size to store.

The default period to store executed queries is 60 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

Filter 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

Edit a query

To edit an executed SQL query, right-click it in the 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 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?