How to track queries in SQL Server Management Studio and Visual Studio

In this article, we will describe the features in ApexSQL Complete that track SQL queries whether they be executed or unsaved and save them in the appropriate folders/files for later use.

ApexSQL Complete is a free add-in for SSMS and Visual Studio that speeds up coding and improve productivity using features such as SQL snippets, auto-replacements, auto inserting statements and more.

Track executed queries

To keep track of executed queries in SSMS and Visual Studio, check whether the Log executed queries option under the Executed queries tab enabled. By default, this option is checked:

From now on, all the queries that are executed in SSMS or Visual Studio will be saved into the ExecutedQueries.xml file. By default, this file is located under C:\Users\<UserName>\AppData\Local\ApexSQL\ApexSQLComplete\ExecutedQueries path.

Quick tip icon

Quick tip:

The information about executed queries is managed in such a way that a separate folder is created based on the date (e.g. 03-23-2016, 02-24-2016) and each folder contains an ExecutedQueries.xml file in which is stored information about executed queries for that date.

The ExecutedQueries.xml file contains information about the user who executed a query, the date and time of the execution, duration of the execution, status of the query (whether committed successfully or with an error), from which database was the query executed and query code that is executed:

To view executed queries, go to the ApexSQL Complete menu and from the drop down list choose the Executed queries command:

This will open the Executed queries form:

On startup, the Executed queries form, will show the list of all executed queries for the particular set of date that is set in the Default period option under the Executed queries tab:

Additionally, a number of executed queries that will be displayed in the list can be changed by changing the date in the Form and the To combo boxes:

Reusing executed queries

Content of executed queries can be copied from the details pane, or double-click on the desired query from the list, it will automatically put the query content in a new query window:

Track unsaved queries

In a situation when an accidentally closed unsaved query, causes potential loss of work, the Tab navigation option in ApexSQL Complete add-in can be very useful.

In order to use the Tab navigation option to start tracking any opened or closed tabs, the Enable tab navigation option must be enabled. From the Options form in the Tab navigation tab, select the Enable tab navigation option:

Quick tip icon

Quick tip:

By default the Enable tab navigation option under the Tab navigation tab is disabled.

To use this option, the Tab navigation pane must be initiated. From ApexSQL Complete menu, select the Tab navigation option:

Which will show all opened tabs in the Opened section:

Closed tabs, no matter whether are saved or not, will be saved in the Recently closed section:

By default, each of the opened and recently closed tabs are saved as an XML file here C:\Users\<current_user>\AppData\Local\ApexSQL\ApexSQLComplete\TabNavigation.

Quick tip icon

Quick tip:

XML files are placed in the appropriate folder, which title contains the version of SSMS/VS where XML files are created (e.g. SQL Server Management Studio 2014, Microsoft Visual Studio 2013).

Reusing unsaved queries

The content of unsaved queries can be copied from the details pane and, also by double-clicking on the query from the list in the Recently closed tab. The latter will open the query content in a new query window and remove the clicked query from the Recently closed tab list and move to the Opened tab list:

The content of the Tab navigation and the Executed queries folder can be copied and moved to another machine where ApexSQL Complete is installed.

March 31, 2016