such that the least number of resources are used.
Database for the tutorial
We will be using the AdventureWorks database in this tutorial for showing
various commands and their
optimized solutions. You can download the database from
here
.
AdventureWorks database is
a sample database provided by Microsoft SQL Server.
This is a standard
database used for showing day-to-day transaction processing for a business.
Scenarios include sales,
customer management, product management, and human resources.
For more information on the tables, relationships of the database, you can visit this
link
.
Metrics for analyzing query performance for SQL Query Optimization
There are several metrics for calculating the cost of the query in terms of space, time, CPU utilization, and
other resources:
1. Execution Time: The most important metrics to analyze the query performance is the execution time of
the query. Execution time/Query duration is defined as the time taken by the query to return the rows from
the database. We can find the query duration using the following commands:
SET STATISTICS TIME ON SELECT * FROM SalesLT.Customer;
By using
STATISTICS TIME ON,
we can see the parse time,
compile-time,
execution time,
and completion
time of the query.
Parse and Compile Time: The time taken to parse and compile the query to check the syntax of the query
is termed Parse and Compile time.
Execution Time: The CPU time used by the query to fetch the data is termed Execution time.
Do'stlaringiz bilan baham: