Categories: TSQL

T-SQL Tuesday #149 – T-SQL Advice you’d give to your younger self

It’s the second Tuesday of the month, so it’s time for the T-SQL Tuesday blog party! This month’s topic is chosen by Camila Henrique (blog): what T-SQL advice would you give to your younger self? Here’s a little list I’d tell anyone starting out with T-SQL:

  • you can configure most tools that when you hit Tab, it enters 4 spaces instead
  • get the difference between set-based processing and RBAR (aka cursors)
  • learn the different types of JOINs
  • don’t try to write one giant SQL statement that does it all. Either use common table expressions to clarify your code, or split up and use (temp) tables to store intermediate results.
  • learn how indexes work. They’re one of the most fundamental things to learn when it comes to performance tuning.
  • learn about SARGable queries, so your indexes are actually used
  • learn about window functions, because they’re awesome. I can absolutely recommend the book by Itzik Ben-Gan.
  • put everything in source control
  • comment your code
  • don’t spend too much time on hierarchyid, XML and other exotic stuff, nobody uses it 🙂 (but you need to learn it for the certification exams)
  • learn about dynamic SQL and how you can generate stuff based on metadata
  • learn the logical query processing order. E.g. SELECT comes last, FROM comes first.
  • get the subtle difference between DISTINCT and GROUP BY to remove duplicates. And don’t forget UNION and UNION ALL are not the same.


------------------------------------------------
Do you like this blog post? You can thank me by buying me a beer 🙂
Koen Verbeeck

Koen Verbeeck is a Microsoft Business Intelligence consultant at AE, helping clients to get insight in their data. Koen has a comprehensive knowledge of the SQL Server BI stack, with a particular love for Integration Services. He's also a speaker at various conferences.

Recent Posts

Free webinar – Tackling the Gaps and Islands Problem with T-SQL Window Functions

I'm hosting a free webinar at MSSQLTips.com at the 19th of December 2024, 6PM UTC.…

5 days ago

dataMinds Connect 2024 – Session Materials

The slides and scripts for my session "Tackling the Gaps & Islands Problem with T-SQL…

4 weeks ago

Connect to Power BI as a Guest User in another Tenant

Sometimes your Microsoft Entra ID account (formerly known as Azure Active Directory) is added as…

2 months ago

How to use a Script Activity in ADF as a Lookup

In Azure Data Factory (ADF, but also Synapse Pipelines and Fabric Pipelines), you have a…

4 months ago

Database Build Error – Incorrect syntax near DISTINCT

I wrote a piece of SQL that had some new T-SQL syntax in it: IS…

4 months ago

Speaking at dataMinds Connect 2024

I'm very excited to announce I've been selected as a speaker for dataMinds Connect 2024,…

5 months ago