Sofia, Bulgaria | 9-10 October SQL Querying Tips & Techniques Richard Campbell.

Slides:



Advertisements
Similar presentations
Working with Tables 1 of 5. Working with Tables 2 of 5.
Advertisements

Ashley Ohmann June 20, * What is Custom SQL? * What can I do with it? * Join conditions * Unions and Self Joins * Ranks * Derived Tables.
Big Data Working with Terabytes in SQL Server Andrew Novick
Module 7 Designing Queries for Optimal Performance.
The Most Simplest & Shortest Route to Learning SQL URL: sqlinminutes.blogspot.comhttp:// sqlinminutes.blogspot.com Authored by: Riaz Ahmed ISBN-13:
Fundamentals, Design, and Implementation, 9/e Chapter 7 Using SQL in Applications.
Introduction to Structured Query Language (SQL)
Concepts of Database Management Sixth Edition
Inner join, self join and Outer join Sen Zhang. Joining data together is one of the most significant strengths of a relational database. A join is a query.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
INFORMATION TECHNOLOGY IN BUSINESS AND SOCIETY SESSION 16 – SQL SEAN J. TAYLOR.
A Linear Regression Algorithm Using Windowing Functions KEVIN MCCARTY.
Sofia, Bulgaria | 9-10 October TSQL Enhancements in SQL Server 2005 Stephen Forte CTO, Corzen Inc Microsoft Regional Director NY/NJ (USA) Stephen Forte.
Sofia, Bulgaria | 9-10 October SQL Server 2005 High Availability for developers Vladimir Tchalkov Crossroad Ltd. Vladimir Tchalkov Crossroad Ltd.
Sofia, Bulgaria | 9-10 October Using XQuery to Query and Manipulate XML Data Stephen Forte CTO, Corzen Inc Microsoft Regional Director NY/NJ (USA) Stephen.
ADVANCE T-SQL: WINDOW FUNCTIONS Rahman Wehelie 7/16/2013 ITC 226.
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
10/31/2012ISC239 Isabelle Bichindaritz1 SQL Graphical Queries Design Query By Example.
INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
SQL advanced select using Oracle 1 7. Multiple Tables: Joins and Set Operations 8. Subqueries: Nested Queries.
SQL/Lesson 4/Slide 1 of 45 Using Subqueries and Managing Databases Objectives In this lesson, you will learn to: *Use subqueries * Use subqueries with.
Database Systems Microsoft Access Practical #3 Queries Nos 215.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Mark Inman U.S. Navy (Naval Sea Logistics Center) Session #213 Analytic SQL for Beginners.
Intro to SQL Management Studio. Please Be Sure!! Make sure that your access is read only. If it isn’t, you have the potential to change data within your.
BACS 287 Structured Query Language 1. BACS 287 Visual Basic Table Access Visual Basic provides 2 mechanisms to access data in tables: – Record-at-a-time.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
T-SQL: Simple Changes That Go a Long Way DAVE ingeniousSQL.com linkedin.com/in/ingenioussql.
Sofia, Bulgaria | 9-10 October The Query Governor Richard Campbell Stephen Forte Richard Campbell Stephen Forte.
More Windowing Functions KEVIN MCCARTY. What are Windowing Functions Again? Introduced in SQL Server 2005 (SQL 2003 Standard) Used to provide operations.
O FFICE M ANAGEMENT T OOL - II B BA -V I TH. Abdus Salam2 Week-7 Introduction to Query Introduction to Query Querying from Multiple Tables Querying from.
In this session, you will learn to: Use functions to customize the result set Summarize and group data Objectives.
Course FAQ’s I do not have any knowledge on SQL concepts or Database Testing. Will this course helps me to get through all the concepts? What kind of.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
A Guide to SQL, Eighth Edition Chapter Five Multiple-Table Queries.
1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Access 2010 by Robert Grauer, Keith Mast, and Mary Anne.
05 | SET Operators, Windows Functions, and Grouping Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program.
Sofia, Bulgaria | 9-10 October SQL Server Profiler Richard Campbell.
Session id: Darrell Hilliard Senior Delivery Manager Oracle University Oracle Corporation.
SQL. Originally developed by IBM Standardized in 80’s by ANSI and ISO Language to access relational database and English-like non-procedural Predominant.
1 Copyright © 2009, Oracle. All rights reserved. Oracle Business Intelligence Enterprise Edition: Overview.
1 SQL: The Query Language. 2 Example Instances R1 S1 S2 v We will use these instances of the Sailors and Reserves relations in our examples. v If the.
Manipulating Data Lesson 3. Objectives Queries The SELECT query to retrieve or extract data from one table, how to retrieve or extract data by using.
A Glance at the Window Functions. Window Functions Introduced in SQL 2005 Enhanced in SQL 2012 So-called because they operate on a defined portion of.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
There’s a particular style to it… Rob Hatton
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
6/13/2015 Visit the Sponsor tables to enter their end of day raffles. Turn in your completed Event Evaluation form at the end of the day in the Registration.
DBI309: Using SQL Server 2012 Window Functions to Solve Common T-SQL Challenges Steven Wang MCITP – BI, Database Developer and DBA.
1. Advanced SQL Functions Procedural Constructs Triggers.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
Doing fast! Optimizing Query performance with ColumnStore Indexes in SQL Server 2012 Margarita Naumova | SQL Master Academy.
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
Relational Database Design
© 2016, Mike Murach & Associates, Inc.
T-SQL: Simple Changes That Go a Long Way
T-SQL: Simple Changes That Go a Long Way
Database Systems: Design, Implementation, and Management Tenth Edition
Using Window Ranking, Offset, and Aggregate Functions
Principles of report writing
Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Data Analysis with SQL Window Functions
What query folding means to self-service BI projects
Four Rules For Columnstore Query Performance
Chapter 9 Query-by-Example Pearson Education © 2009.
Database Systems: Design, Implementation, and Management Tenth Edition
Build on-the-fly reporting with Dynamic SQL
Intermediate Query Structure and Development
T-SQL: Simple Changes That Go a Long Way
Presentation transcript:

Sofia, Bulgaria | 9-10 October SQL Querying Tips & Techniques Richard Campbell

Sofia, Bulgaria | 9-10 October Who Am I? ●Consultant in development methodology and high scaling systems ●Microsoft Regional Director ●Partner in PWOP Productions ●Author of Advisor Answers ● ●C●Consultant in development methodology and high scaling systems ●M●Microsoft Regional Director ●P●Partner in PWOP Productions ●A●Author of Advisor Answers ●w●

Sofia, Bulgaria | 9-10 October PWOP Productions ●.NET Rocks! ●Internet Audio Talkshow for.NET Developers ● ●dnrTV ●Screencast (see the code!) ● ●.●.NET Rocks! ●I●Internet Audio Talkshow for.NET Developers ●w● ●d●dnrTV ●S●Screencast (see the code!) ●w●

Sofia, Bulgaria | 9-10 October Agenda ●Subqueries & CTEs ●Self-Joins & Recursion ●Ranking Functions ●The Crosstab Problem ●Deadlocks Tricks ●Subqueries & CTEs ●Self-Joins & Recursion ●Ranking Functions ●The Crosstab Problem ●Deadlocks Tricks

Sofia, Bulgaria | 9-10 October Advanced Queries ●No teaching the basics here ●We presume you already understand SELECT, JOIN, WHERE, GROUP BY, ORDER BY… ●And now you’re looking for more ●No teaching the basics here ●We presume you already understand SELECT, JOIN, WHERE, GROUP BY, ORDER BY… ●And now you’re looking for more

Sofia, Bulgaria | 9-10 October Subqueries ●Can act much like a join ●More efficient at finding general matches ●Good for comparing a set to a set ●Locating ranged values ●Finding duplicates ●Can act much like a join ●More efficient at finding general matches ●Good for comparing a set to a set ●Locating ranged values ●Finding duplicates

Sofia, Bulgaria | 9-10 October Common Table Expressions ●Uses ANSI syntax and semantics ●Very similar to a view, but embedded in the query ●May be used in front of SELECT, UPDATE, DELETE, INSERT ●Uses ANSI syntax and semantics ●Very similar to a view, but embedded in the query ●May be used in front of SELECT, UPDATE, DELETE, INSERT

Sofia, Bulgaria | 9-10 October Self-Joins ●Joining a Table to Itself ●Classic scenario: the organizational chart ●Each employee record has an employee_ID and a ReportsTo_ID that points to another employee ●There can be one (and only one) report path ●Joining a Table to Itself ●Classic scenario: the organizational chart ●Each employee record has an employee_ID and a ReportsTo_ID that points to another employee ●There can be one (and only one) report path

Sofia, Bulgaria | 9-10 October Recursive Queries ●This is the main reason MSFT introduced the CTEs ●Recursion is achieved by allowing the CTE refer to itself ●Such CTE must have special syntax ●WITH REC_CTE as ●(SELECT1 UNION ALL SELECT2) ●This is the main reason MSFT introduced the CTEs ●Recursion is achieved by allowing the CTE refer to itself ●Such CTE must have special syntax ●WITH REC_CTE as ●(SELECT1 UNION ALL SELECT2)

Sofia, Bulgaria | 9-10 October Ranking Queries ●Self-joins can be used to rank data ●Join on a >= expression ●Use COUNT(*) to set rank ●When two rows are ranked the same, they both get the greater value ●Self-joins can be used to rank data ●Join on a >= expression ●Use COUNT(*) to set rank ●When two rows are ranked the same, they both get the greater value

Sofia, Bulgaria | 9-10 October Ranking Functions ●SQL Server adds 4 ranking functions: ●Row_Number() ●RANK() ●DENSE_RANK() ●nTile(n) ●Ability to partition and “window” these functions ●Ability to perform aggregate operations over the ranking functions ●Can be used with User Defined Functions ●SQL Server adds 4 ranking functions: ●Row_Number() ●RANK() ●DENSE_RANK() ●nTile(n) ●Ability to partition and “window” these functions ●Ability to perform aggregate operations over the ranking functions ●Can be used with User Defined Functions

Sofia, Bulgaria | 9-10 October The Crosstab Problem ●What’s a Crosstab? ●Turning rows into columns ●For example: ●Sales by Product Per Month ●Sales by Product Per Salesperson ●Etc… ●What’s a Crosstab? ●Turning rows into columns ●For example: ●Sales by Product Per Month ●Sales by Product Per Salesperson ●Etc…

Sofia, Bulgaria | 9-10 October The Rozenshtein Method ●Taken from Optimizing Transact-SQL: Advanced Programming Techniques ●Uses boolean aggregates ●Each column has a numeric expression that resolves each row as a zero or one ●Taken from Optimizing Transact-SQL: Advanced Programming Techniques ●Uses boolean aggregates ●Each column has a numeric expression that resolves each row as a zero or one

Sofia, Bulgaria | 9-10 October PIVOT and UNPIVOT ●PIVOT ●Transforms a set of rows to columns ●Similar to Access TRANSFORM ●Useful for open schemas/OLAP scenarios ●UNPIVOT ●Reverse operation of PIVOT ●PIVOT ●Transforms a set of rows to columns ●Similar to Access TRANSFORM ●Useful for open schemas/OLAP scenarios ●UNPIVOT ●Reverse operation of PIVOT

Sofia, Bulgaria | 9-10 October Deadlocks ●What is a deadlock? ●Connection A locks table 1, needs table 2 ●Connection B locks table 2, needs table 1 ●Someone has to lose ●What is a deadlock? ●Connection A locks table 1, needs table 2 ●Connection B locks table 2, needs table 1 ●Someone has to lose

Sofia, Bulgaria | 9-10 October Deadlocks ●Solution: ●Don’t ever do that! ●Always update tables in the same order ●Plan an order of updates, always follow it ●Do your updates in stored procedures ●Even then, sometimes you’ll get deadlocks ●(busy databases can be funny things) ●Solution: ●Don’t ever do that! ●Always update tables in the same order ●Plan an order of updates, always follow it ●Do your updates in stored procedures ●Even then, sometimes you’ll get deadlocks ●(busy databases can be funny things)

Sofia, Bulgaria | 9-10 October Questions?

Sofia, Bulgaria | 9-10 October Please fill out the survey forms! They are the key to amazing prizes that you can get at the end of each day Thank you!

Sofia, Bulgaria | 9-10 October