Professional Documents
Culture Documents
QDUS Session 28
QDUS Session 28
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Objectives
Ver.
Ver. 1.0
1.0 Slide
Slide11of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Monitoring Performance
Ver.
Ver. 1.0
1.0 Slide
Slide22of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Monitoring Performance by Using SQL Server Profiler
Ver.
Ver. 1.0
1.0 Slide
Slide33of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Monitoring Performance by Using SQL Server Profiler (Contd.)
A trace:
Enables you to specify the events and the values for the
events that are to be monitored.
Allows you to apply filters.
Settings can be stored in a template.
SQL Server Profiler supports the following types of
templates:
Default template
Custom template
a user-defined
Is the template
template shipped that
with SQLcanServer
be reused.
Profiler. Under the default
template, SQL Server captures typical values from a trace, such as start
time, end time, and login name.
Ver.
Ver. 1.0
1.0 Slide
Slide44of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Monitoring Performance by Using SQL Server Profiler (Contd.)
Ver.
Ver. 1.0
1.0 Slide
Slide55of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Monitoring Performance by Using DMVs
Ver.
Ver. 1.0
1.0 Slide
Slide66of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Monitoring Performance by Using DMVs (Contd.)
Using DMVs
Ver.
Ver. 1.0
1.0 Slide
Slide77of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Just a minute
Which one of the following DMVs will you use to view the
connection information of all the available sessions?
sys.dm_exec_requests
sys.dm_exec_connections
sys.dm_exec_sessions
sys.dm_sql_referenced_entities
Solution:
sys.dm_exec_connections
Ver.
Ver. 1.0
1.0 Slide
Slide88of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Just a minute
Solution:
sys.dm_io_backup_tapes, sys.dm_io_pending_io_requests,
and sys.dm_io_cluster_shared_drives
Ver.
Ver. 1.0
1.0 Slide
Slide99of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Monitoring Performance by Using Database Engine Tuning Advisor
Ver.
Ver. 1.0
1.0 Slide
Slide10
10of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Optimizing Performance
Ver.
Ver. 1.0
1.0 Slide
Slide11
11of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Implementing Statistics
Statistics:
Refers to the information that the server collects about the
distribution of data in columns and indexes.
Is created automatically when indexes are created.
Can be automatically created and updated by SQL Server.
Can also be created manually by using the CREATE
STATISTICS statement.
Being maintained on a table can be listed by using the
sp_helpstats system stored procedure.
Can also be updated manually by using the UPDATE
STATISTICS statement.
Ver.
Ver. 1.0
1.0 Slide
Slide12
12of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Implementing Statistics (Contd.)
Ver.
Ver. 1.0
1.0 Slide
Slide13
13of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Implementing Statistics (Contd.)
Ver.
Ver. 1.0
1.0 Slide
Slide14
14of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Implementing Plan Guides
Plan guides:
Allow you to attach query hints or a fixed query plan with the
query to optimize its performance.
Use the OPTION clause to attach a query hint.
Are of the following types:
OBJECT
SQL
TEMPLATE
Ver.
Ver. 1.0
1.0 Slide
Slide15
15of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Demo: Monitoring the Database
Problem Statement:
You are the database administrator at AdventureWorks, Inc.
Sam, one of the developers, has notified you that the query is
taking a long time to execute. To resolve the issue, you have
traced the queries being executed by Sam and stored the
workload in a file named SamTrace.txt. What should be done
to reduce the execution time taken by the queries?
Ver.
Ver. 1.0
1.0 Slide
Slide16
16of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Demo: Monitoring the Database (Contd.)
Solution:
To improve the performance of the queries, you should put this
trace file into SQL Server Database Tuning Advisor. For the
same, you need to perform the following tasks:
1. Start the analysis.
2. Set the tuning options.
3. Get the recommendations.
Ver.
Ver. 1.0
1.0 Slide
Slide17
17of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Tracking Data Changes
Ver.
Ver. 1.0
1.0 Slide
Slide18
18of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Using CDC
Ver.
Ver. 1.0
1.0 Slide
Slide19
19of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Using Change Tracking
You can also use the change tracking method to track the
changes made in the tables.
This method only captures the fact that certain changes
were made in the rows in a table. It, however, fails to
highlight the content that was changed.
To use change tracking, you need to perform the following
steps:
1. Enable change tracking on a database.
2. Enable change tracking on a table.
3. Implement change tracking.
Ver.
Ver. 1.0
1.0 Slide
Slide20
20of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Using Change Tracking (Contd.)
Ver.
Ver. 1.0
1.0 Slide
Slide21
21of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Demo: Tracking Database Changes
Problem Statement:
The sales manager of AdventureWorks, Inc. needs to update
the e-mail address of an employee having ContactID 3, in the
Contact table. You need to track the updations made in the
Contact table by applying CDC.
Ver.
Ver. 1.0
1.0 Slide
Slide22
22of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Demo: Tracking Database Changes (Contd.)
Solution:
To track the updations made in the Contact table, you need to
perform the following tasks:
1. Enable CDC on the Contact table.
2. Update the Contact table.
3. View the track changes.
Ver.
Ver. 1.0
1.0 Slide
Slide23
23of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Summary
Ver.
Ver. 1.0
1.0 Slide
Slide24
24of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
Summary (Contd.)
Ver.
Ver. 1.0
1.0 Slide
Slide25
25of
of50
26
Querying
QueryingData
and Using SQL Data
Managing Server
Using SQL Server
What’s Next?
Ver.
Ver. 1.0
1.0 Slide
Slide26
26of
of50
26