Your SlideShare is downloading. ×
Sql query analyzer & maintenance
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Sql query analyzer & maintenance


Published on

16 februari 2011 …

16 februari 2011

Published in: Technology

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. SQL Analyzer tools&Database Maintenance
    Hans Schellingerhoudt
    16 februari 2011
    Presentation is createdforNspyre Technologie Group .Net
  • 2. Program
  • 20.
    • SQL Query Analyzer
  • 21. Introduction
    Introduction “Query Analyzer”
    • SQL Query Analyzer no longer exist as single “tool” (since SQL Server 2005/2008).
    • 22. Integrated in Management Studio.
    • 23. Visualizes execution plan / statistics information
    • 24. A query execution plan outlines how the SQL Server query optimizer actually ran (or will run).
    • 25. An execution plan, simply put, is the result of the query optimizer's attempt to calculate the most efficient way to imple­ment the request represented by the T-SQL query you sub­mitted.
    • 26. You can use the execution plan to identify the exact piece of SQL code that is causing the problem
  • 27. Execution plan
    Facts about the SQL Query Analyzer
    • SQL Query Analyzer has number of steps, one of them is the query optimizer.
    • 28. Optimizer uses the statistics to calculate the cost-based plan, the optimal way to execute the query. It calculates a number of plans.
    • 29. Statistics exists for relevant columns and indexes.
    • 30. Estimated execution plan is the output of the optimizer.
    • 31. Actual execution plan is the output of the actual query execution
    • 32. Estimated and Actual execution plan can differ if statistics is not accurate.
  • 33. Column statistics
    Column statistics
    Generally, column statistics, if needed by the Query Optimizer, are generated automatically by SQL Server when queries are being optimized by the Query Optimizer.SQL Server's engine will update the statistic when:
    • When data is initially added to an empty table
    • 34. The table had > 500 records when statistics were last collected and the lead column of the statistics object has now increased by 500 records since that collection date
    • 35. The table had < 500 records when statistics were last collected and the lead column of the statistics object has now increased by 500 records + 20% of the row count from the previous statistics collection date
    -There are two cases when SQL Server will not automatically create column statistics, even when they fit the criteria described above. These include: when the costs needed to create the column statistics are larger than the costs of the query plan; and when SQL Server is too busy.
  • 36. Column statistics
    Column statistics continued
    There are two cases when SQL Server will not automatically create column statistics, even when they fit the criteria described in the previous sheet. These include:
    • When the costs needed to create the column statistics are larger than the costs of the query plan;
    • 37. And when SQL Server is too busy.
  • 38. Run analyzer
    How to run the SQL Query Analyser (and User statistics):
    • Open “new query” in management studio.
    • 39. Swith on the buttons “Actual execution plan” (and “User statistics”).
    • 40. Run the query and the information will be shown in the execution plan (en user statistics) windows.
  • 41. Run analyzer
    Use the results of the execution plan:
  • 42. Query tuning
    If you see any of the following in an execution plan, you should consider them warning signs and investigate them for potential performance problems:
    Each of them are less than ideal from a performance perspective.
  • 45. Optimization
    General optimalisation steps:
    Use primairy keys
    Use foreign keys
    Use constrains
    Create indexes for the where clauses
    User ‘included’ indexes for query results (read)
    Use the execution plan for further optimalisation steps.
    Use the profiles, see next subject, verification of the previous steps.
    Note: For write actions it is better to have not to mutch indexes.
    Use these by default in the design process, should be … for most of the joins.
  • 46. User statistics
    User Statistics introduction:
    • Do not relate queries execution plan with query cost.
    • 47. The amount of the data returned is considerably large, which is causing any query to run slow.
    • 48. Looking at the result set and looking at the user Statistics.
    • 49. Measure how much data is retrieved from server.
    • 50. It will capture details for different trials and they are compared with each other.
  • 51. User statistics
    Green arrows indicate improved statistics and red arrows indicate degrading statistics.
    A maximum of 10 trials are averaged in the display window
  • 52. Demo
    Demo Query Analyser
    - Execution plan
    - User statistics
  • 53.
    • Otheranalyzer tools (profiler)
  • 54. Profilerintroduction
    Database profiler
  • 55. Profiler
    Using Profiler with the Database Engine Tuning Advisor
  • 56. TuningAdvisor
    Using Profiler with the Database Engine Tuning Advisor
  • 57. TuningAdvisor
    Using Profiler with the Database Engine Tuning Advisor
  • 58. TuningAdvisor
  • 59.
    • Database Maintenance
  • 60. IntroductionMaintenance
    Database maintenancetasks
    Managing data and transaction log files
    Eliminating index fragmentation
    Ensuring accurate, up-to-date statistics
    Establishing an effective backup strategy
  • 61. Maintenancetasks
    Transaction log files
    Transaction log is separated file.
    Transaction file will grow for each database change.
    The steps of grow can be configured.
  • 62. Maintenancetasks
    Index fragmentation
    Indexes are used for performance
    Indexes will be fragmented by delete, merge and insert actions.
    Indexes can also be fragmented by database (auto)shrink. Don’t use shrink!
  • 63. Maintenancetasks
    Accurate, up-to-date statistics
    Provides information nessessary for the optimizer to make its calculation (Estimated and actual execution plan should be the same).
    Rebuild the statistics
  • 64. Maintenancetasks
    Effective backup strategy
    Backup the actual data situation
    Back in time (transaction time)
  • 65. Maintenancetasks
    Automatic processes in SQL Server:
    • SQL-T statements in a JOB scheduling
    Executed with SQL statements for dedicated actions.
    Don’t use this for maintenance, use the Maintenance Plans.
    • Maintenance Plans
    Part of the database management tools.
    Part is called Maintenance Plans.
    Note: May generate unwanted overhead on a production system and “locks”. Plan maintenance at a ‘correct’ moment.
  • 66. Maintenancetasks
    Demo Maintenance Plans
  • 67. Conclusion
    General Conclusion
    • Use default design roles (create keys and indexes).
    • 68. Check important queries with an execute plan.
    • 69. Run profiler when you expect performance issues and on regular basis.
    • 70. Schedule maintenance Plans for the normal maintenance tasks.
    Note: SQL Server instance installation and configuration is not part of this presentation. But for performance issues, your most ‘important’ databases/tables, could or must be configured on hardware/spindels with a fast raid configuration!
  • 71. References
    Link references:
    E-Books* references:
    -SQL Server Execution Plans by Grant Fritchey, ISBN 978-1-906434-04-5
    -Mastering SQL Server Profiler by Brad M McGehee, ISBN 978-1-906434-11-3
    *eBooks also used for some pictures.
  • 72. Questions?
    End of presentation