Presentation is loading. Please wait.

Presentation is loading. Please wait.

Stop Doing That! Common T-SQL Anti-Patterns

Similar presentations


Presentation on theme: "Stop Doing That! Common T-SQL Anti-Patterns"— Presentation transcript:

1 Stop Doing That! Common T-SQL Anti-Patterns
~ Wolf ~ This template can be used as a starter file for presenting training materials in a group setting. Sections Right-click on a slide to add sections. Sections can help to organize your slides or facilitate collaboration between multiple authors. Notes Use the Notes section for delivery notes or to provide additional details for the audience. View these notes in Presentation View during your presentation. Keep in mind the font size (important for accessibility, visibility, videotaping, and online production) Coordinated colors Pay particular attention to the graphs, charts, and text boxes. Consider that attendees will print in black and white or grayscale. Run a test print to make sure your colors work when printed in pure black and white and grayscale. Graphics, tables, and graphs Keep it simple: If possible, use consistent, non-distracting styles and colors. Label all graphs and tables.

2 Resources to use: #sqlsatcharlotte #sqlhelp #sqlserver
Add slides to each topic section as necessary, including slides with tables, graphs, and images. See next section for sample table, graph, image, and video layouts. #sqlsatcharlotte #sqlhelp #sqlserver

3 About Wolf DBA for 16 years, SQL Server/Oracle combination
At RDX for 6 years. “Manager – SQL Server Performance Tuning” Works with a variety of clients and challenges Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important. Introduce each of the major topics. To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.

4 There are 2 types of people in this world…

5 Star Trek: Next Generation - http://i.stack.imgur.com/NTsOF.jpg

6 What we will focus on 1 2 3 Scalar-Value Function as part of Select
State of the Union 2 Common Table Expressions 3 SARGability 4 This is another option for an Overview slide.

7 Scalar-Valued Function in the Select
Use a section header for each of the topics, so there is a clear transition to the audience. Scalar-Valued Function in the Select

8 What is a Scalar-Valued Function?
Scalar functions return a single data value of the type defined in the RETURNS clause. Supports nearly all data types with the exception of text, ntext, image, and timestamp Let’s see how they work Summarize presentation content by restating the important points from the lessons. What do you want the audience to remember when they leave your presentation? Save your presentation to a video for easy distribution (To create a video, click the File tab, and then click Share.  Under File Types, click Create a Video.)

9 What did we see Scalar-Valued Function is great to reuse code
When used as part of the select, the function will read, Row by Agonizing Row(RBAR) Summarize presentation content by restating the important points from the lessons. What do you want the audience to remember when they leave your presentation? Save your presentation to a video for easy distribution (To create a video, click the File tab, and then click Share.  Under File Types, click Create a Video.)

10 Use a section header for each of the topics, so there is a clear transition to the audience.
State of the Union

11 What is a Union? Union combines the results of two or more queries into a single result set that includes all the rows that belong to all queries in the union. Union is a great way to give a unique results set from different queries. A Union specifies that multiple result sets are to be combined and returned as a single result set. Let’s see how they work Summarize presentation content by restating the important points from the lessons. What do you want the audience to remember when they leave your presentation? Save your presentation to a video for easy distribution (To create a video, click the File tab, and then click Share.  Under File Types, click Create a Video.)

12 What did we see? The union operator has its uses, but we can see that those uses come at a cost of reads and tempdb usage. At times, we may not have an alternative, but we need to be aware of the costs and use this functionality accordingly. Summarize presentation content by restating the important points from the lessons. What do you want the audience to remember when they leave your presentation? Save your presentation to a video for easy distribution (To create a video, click the File tab, and then click Share.  Under File Types, click Create a Video.)

13 Common Table Expressions(CTE)
Use a section header for each of the topics, so there is a clear transition to the audience. Common Table Expressions(CTE)

14 What are CTE? A common table expression (CTE) can be thought of as a defined derived table that is defined within the execution scope of a single SELECT, INSERT, UPDATE, DELETE, or CREATE VIEW statement. Unlike a derived table, a CTE can be self- referencing and can be referenced multiple times in the same query. Add slides to each topic section as necessary, including slides with tables, graphs, and images. See next section for sample table, graph, image, and video layouts.

15 What did we see? CTE are a defined derived table
With small recordsets and simple queries, they are acceptable They have no statistics or indexes available. They will not scale well Summarize presentation content by restating the important points from the lessons. What do you want the audience to remember when they leave your presentation? Save your presentation to a video for easy distribution (To create a video, click the File tab, and then click Share.  Under File Types, click Create a Video.)

16 Use a section header for each of the topics, so there is a clear transition to the audience.
SARGable

17 What is a SARGability? In relational databases, a condition (or predicate) in a query is said to be sargable if the DBMS engine can take advantage of an index to speed up the execution of the query. The term is derived from a contraction of Search ARGument ABLE. As DBAs, we do our best to write the queries to take advantage of the indexes as best we can. Searching! Seek and Destroy! Add slides to each topic section as necessary, including slides with tables, graphs, and images. See next section for sample table, graph, image, and video layouts.

18 What did we see? When we don’t take advantage of SARGability, we make the database work much harder than it needs to. Use “LIKE”, built-in functions and scalar- valued functions sparingly. Summarize presentation content by restating the important points from the lessons. What do you want the audience to remember when they leave your presentation? Save your presentation to a video for easy distribution (To create a video, click the File tab, and then click Share.  Under File Types, click Create a Video.)

19 Forest Gump: http://funnyand

20

21 Metallica - Seek & Destroy (Live) [Quebec Magnetic] https://youtu

22 Microsoft Engineering Excellence
Questions? Microsoft Confidential


Download ppt "Stop Doing That! Common T-SQL Anti-Patterns"

Similar presentations


Ads by Google