Presentation is loading. Please wait.

Presentation is loading. Please wait.

Exploring common table expressions

Similar presentations


Presentation on theme: "Exploring common table expressions"— Presentation transcript:

1 Exploring common table expressions
We need to go deeper Exploring common table expressions Gothenburg, Sweden

2 Primary sponsors

3 The others… Gothenburg, Sweden

4 Don’t miss Evaluations The Raffle

5 We need to go deeper: Exploring CTEs
Daniel Hutmacher SQL Server developer and independent contractor by day. Spinning instructor by night. I love coffee, travel, cycling, loud music and making SQL Server queries go really fast. Like, stupid-fast. Gothenburg, Sweden

6 We need to go deeper: Exploring CTEs
Common table expressions Gothenburg, Sweden

7 We need to go deeper: Exploring CTEs
Script 01 Gothenburg, Sweden

8 We need to go deeper: Exploring CTEs
CTEs are not materialized A common table expression is a glorified view It won’t materialize Gothenburg, Sweden

9 We need to go deeper: Exploring CTEs
CTEs in sequence You can put multiple CTEs in a statement, separated by commas. You can even UPDATE or DELETE in a CTE. Gothenburg, Sweden

10 We need to go deeper: Exploring CTEs
Recursive CTEs Gothenburg, Sweden

11 We need to go deeper: Exploring CTEs
Script 03 Gothenburg, Sweden

12 We need to go deeper: Exploring CTEs
Recursive CTEs Anchor Recursion Stop condition (optional) OPTION (MAXRECURSION) (optional) Gothenburg, Sweden

13 We need to go deeper: Exploring CTEs
Script 04 Gothenburg, Sweden

14 A simple CTE Anchor Gothenburg, Sweden

15 A simple CTE Recursion Gothenburg, Sweden

16 A simple CTE Stop condition Gothenburg, Sweden

17 The Fibonacci series example
Gothenburg, Sweden

18 The Fibonacci series example
recursion=0 a=0, b=1 Gothenburg, Sweden

19 The Fibonacci series example
recursion=0 a=0, b=1 Gothenburg, Sweden

20 The Fibonacci series example
Gothenburg, Sweden

21 The Fibonacci series example
recursion=recursion+1 Gothenburg, Sweden

22 The Fibonacci series example
Do this... Gothenburg, Sweden

23 The Fibonacci series example
Do this... WHERE a< Gothenburg, Sweden

24 The Fibonacci series example
Do this... a=b, b=a+b Gothenburg, Sweden

25 The Fibonacci series example
recursions<100 ? If not, crash and burn. Gothenburg, Sweden

26 The Fibonacci series example
Gothenburg, Sweden

27 The Fibonacci series example
rinse, repeat... Gothenburg, Sweden

28 We need to go deeper: Exploring CTEs
What can we do with recursive CTEs? Number series String parsing (like split/merge) Hierarchies Dependency trees Gothenburg, Sweden

29 We need to go deeper: Exploring CTEs
Script 05-09 Gothenburg, Sweden

30 We need to go deeper: Exploring CTEs
Bonus: can recursive CTEs be made parallel? Script 10 Gothenburg, Sweden

31 We need to go deeper: Exploring CTEs
Questions! Twitter: @dhmacher Blog: sqlsunday.com Old-school: Gothenburg, Sweden


Download ppt "Exploring common table expressions"

Similar presentations


Ads by Google