How to Use SQL Server Profiler and Tuning Advisor

Introduction

In this article, you will learn how to use SQL Profiler and Database Tuning Advisor to improve the performance of a database.

What is SQL Server Profiler?

Microsoft SQL Server Profiler is a graphical user interface to SQL Trace for monitoring an instance of the Database Engine or Analysis Services. You can capture and save data about each event to a file or table to analyze later. For example, you can monitor a production environment to see which Stored Procedures are affecting performance by executing too slowly.

What is Tuning Advisor?

The tuning advisor helps to get the performance report that is generated by SQL Profiler and provides the appropriate indexing. It takes one or more SQL statements as input and invokes the Automatic Tuning Optimizer to perform SQL tuning on the statements.

Real-Time Example

The following is a real-time example

  • First of all start SQL Server 2008
  • Click on New Query
  • Select Northwind database

Let's fire some select statements.

img1.jpg

Image 1.

Those queries return three tables of data, the first table has 1 record, the second has 9 records and the third has 166 records.

Now let's start SQL Profiler, go to the tools.

img2.jpg

Image 2.

And provide the login credentials to connect.

img3.jpg

Image 3.

You will see it shows the trace properties, like name, provider name, and provider type.

img4.jpg

Image 4.

Now click on the "Run" button.

img5.jpg
Image 5.

You will see that there are many queries running internally but we want only the Northwind report. Let's make some changes to the trace properties.

img6.jpg

Image 6.

Since we are creating this for tuning purposes, select the template for tuning and select the event selection tab and click the "Column filters" button.

img7.jpg

Image 7.

Select the database name and in the statement provide the database name and click "Ok".

img8.jpg

Image 8.

Now run the profiler again, you will see only the Northwind database queries being executed and loading into the report.

img9.jpg

Image 9.

Now stop the profile and save this report as a trace file.

img10.jpg

Image 10.

So the trace file has been saved at the given location and with the given name.

Now the time has come to start the database engine and tuning advisor.

img11.jpg

Image 11.

And now select the workload file that we saved on the local machine and select the database to tune and the "Start analysis" button.

img12.jpg

Image 12.

img13.jpg

Image 13.

Hit the "Start Analysis" button.

img14.jpg

Image 14.

If you get this error then do the following to remove this error.

  • Go to the Tuning Options tab
  • Click the Advanced Options button
  • Check the defined max space for recommendations
  • Enter 5 in the text box
  • Click "Ok"

img15.jpg

Image 15.

Now click "Start Analysis" again.

img16.jpg

Image 16.

img17.jpg

Image 17.

Conclusion

In this article, we learned how to use SQL Profiler and Database tuning advisor to improve the performance of a database.


Similar Articles