T-SQL beginner tips for safer SQL queries
Databases

T-SQL beginner tips for safer SQL queries

by HubSite 365 about Pragmatic Works

Pragmatic Works' recent T-SQL lesson shows five beginner mistakes that can change query results or damage data.

Key insights

  • Justin Vogel covers five common T-SQL mistakes for beginners.
  • TOP without ORDER BY can return rows you do not expect.
  • Use IS NULL and IS NOT NULL instead of = NULL.
  • Old-style comma joins can create Cartesian products.
  • Running UPDATE without WHERE can affect more rows than intended.

Pragmatic Works recently published an 8 minute 50 second YouTube video titled T-SQL Tips and Tricks for Beginners Part 2. In it, Justin Vogel walks through five common T-SQL mistakes and shows how to avoid them when working with SQL Server. The main takeaway is simple: small query habits can affect correctness, performance, and even data safety.

What's new

This second part of the beginner series focuses on mistakes that are easy to make and easy to miss when you are still learning T-SQL. The video starts with the risk of using TOP without ORDER BY, then moves to null handling, join syntax, surrogate date keys, and finally a warning about updating data without a filter. The format is practical rather than theoretical, with each point tied to a specific query pattern.

The material also notes that the guidance is aimed at people learning T-SQL, working in SQL Server Management Studio, or building queries against SQL databases and data warehouses. That makes the lesson relevant not only to beginners, but also to anyone reviewing code that will affect production data.

Why it matters

For database users, the most obvious value is avoiding results that look correct but are not guaranteed to be correct. TOP without ORDER BY can return rows in an order SQL Server does not promise, which matters whenever the exact records returned are important. The same idea applies to null checks: comparing a value with = NULL does not work, so using IS NULL and IS NOT NULL is the safer way to filter missing data.

For admins and developers, the video highlights how query structure can affect performance and risk. Old-style comma joins can create Cartesian products, which multiply rows and can cause serious performance problems. The final example is the most direct operational warning: an UPDATE without a WHERE clause can modify every row in the target table, so checking which records will be affected first is presented as a professional habit.

The video does not mention licensing, rollout stage, or product changes. It is a learning resource rather than a feature announcement, so the practical question is whether the viewer writes or reviews SQL often enough that these mistakes could matter in day-to-day work.

How it works

The video organizes the lesson as a sequence of reminders and demonstrations. The topics named in the description are:

  1. Add ORDER BY to TOP
  2. Use IS NULL
  3. Replace comma joins
  4. Filter integer date keys
  5. SELECT first, then UPDATE

For result-limiting queries, the point is that TOP alone does not define which rows you get. Adding ORDER BY makes the requested order explicit, which is the only way to make the returned rows predictable when order matters.

For missing data, the video says to use IS NULL and IS NOT NULL rather than = NULL. That is the correct pattern for filtering rows where a value is absent. For joins, it warns against old-style comma joins because they can create Cartesian products if the relationship between tables is not handled properly.

The date-key section is specific to data warehouses. The video explains that surrogate date keys, especially integer-based date keys, need to be handled differently from traditional date columns. The final tip is procedural: verify which records will be affected before running a data-changing statement, and do not send an UPDATE without a WHERE clause unless you truly intend to change every row.

Limitations and open questions

The source material gives a clear list of topics, but it does not provide the full code examples or the exact demonstrations shown on screen. It also does not explain the surrogate date key pattern in depth, so readers who are new to data warehousing may need additional context to apply that advice confidently. The material does not mention specific SQL Server versions, compatibility settings, or whether any of the guidance differs across Microsoft SQL services.

Because this is a short beginner video, it focuses on common mistakes rather than broader T-SQL design topics such as indexing, transactions, or error handling. The description also does not state whether the examples are meant only for SQL Server or for other Microsoft SQL-based services as well, although it does say the advice applies to SQL Server and SQL databases and data warehouses.

Sources

Frequently asked questions

What does the video focus on?

It covers five beginner T-SQL mistakes, including TOP without ORDER BY, = NULL comparisons, old-style comma joins, surrogate date keys, and UPDATE without WHERE.

Who is the video for?

The description says it is for people learning T-SQL, working in SQL Server Management Studio, or building queries against SQL databases and data warehouses.

Does the material give full code samples?

No. It lists the topics and explains the risks, but it does not publish the complete code shown in the video.

Does it say anything about licensing or rollout?

No. This is a training video, and the source material does not mention licensing, rollout stage, or availability details.