T-SQL

Examples of TOP syntax

This article is just a short summary of TOP clause variants we can use. Especially the last one with a subquery isn’t so common and can be something new for you. Consider official documentation for more details on TOP usage and if you have any other interesting example don’t hesitate…

Read more
SQL Server

Change in Query Plan Can Affect Query Result Set (Table Spool)

It´s legitimate expectation that a SELECT statement will return consistent results independently on number of rows returned or an internal implementation of query processing. But it is not always true. I will demonstrate it on a simple query using NEWID() function. This function should return new value on every call…
T-SQL

Composable DML

Composable DML is an extension SQL Server 2008 extension of the OUTPUT clause which one was originally published in SQL Server 2005. OUTPUT is generally returning all rows from the DML where it’s used without an option to filter the results set. Composable DML extends this concept for INSERT…SELECT scenarios…
SQL Server

How to prevent views with outdated metadata?

SQL Server is persisting various metadata when a new view is created in SQL Server. When underlying objects are changed later then view metadata aren’t updated automatically and this outdated metadata can cause several issues later. Let’s see one simple example. We will create a dbo.SampleTable table and create view…

Read more