Download presentation
Presentation is loading. Please wait.
1
T-SQL gotchas and power-ups
or things that every developer should know Andrey Nikolov Software developer at Kodar Ltd.
2
Sponsors
3
About me Software developer at Kodar Ltd.
More than 15 years of experience in developing database applications Working with SQL Server since version 2000 MCP, 66% MCSA: SQL Server 2012/2014 KODAR Ltd. Systems for efficient software solutions and optimizations 3 |
4
Gotcha vs Power-Up Gotcha (programming), a counter-intuitive, but documented, behavior in a computer system (as opposed to a bug) In video games, power-ups are objects that instantly benefit or add extra abilities to the game character
5
Agenda Window(ing) functions and OVER clause
Temp tables vs temp variables Using SELECT * in a view Few common mistakes Scalar UDFs Object names Post execution performance analysis Q&A 5 |
6
Window(ing) functions and OVER clause
OVER Syntax: OVER () OVER (ORDER BY [field name]) OVER (PARTITION BY [field name] ORDER BY [field name]) OVER (PARTITION BY [field name] ORDER BY [field name] ROWS|RANGE …) CURRENT ROW, UNBOUNDED PRECEDING, UNBOUNDED FOLLOWING Functions: ROW_NUMBER FIRST_VALUE / LAST_VALUE LAG / LEAD COUNT / SUM / MIN / MAX etc.
7
Temp tables vs temp variables
They are NOT in-memory objects They have different: Scope Transactional behavior Statistics Indexes DDL Parallelism
8
Using SELECT * in a view DEMO
Prevents performance tuning by creating covering indexes Design view – incorrect aliases SELECT * was designed for interactive use
9
Few common mistakes UNION IN vs NOT IN ISNUMERIC SET vs SELECT
ORDER BY MONEY Aaron Bertrand Performance / Storage Comparisons : MONEY vs. DECIMAL (images disappeared few months ago).
10
Scalar UDFs They are convenient for code reuse
Their execution is not visible in actual execution plans They are executed for each row They rarely perform well
11
Object names DEMO
12
Post execution performance analysis
sys.dm_exec_query_stats sys.dm_exec_sql_text sys.dm_exec_query_plan sys.dm_exec_plan_attributes
13
Q&A
14
Sponsors
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.