A function that returns a table works like a view that takes parameters. This post builds inline table valued functions over a small product table, compares them with a view and a scalar function, uses them with CROSS APPLY, and shows the two common mistakes with parentheses. Every result comes from SQL Server 2025.
Backing Up the Service Master Key and Database Master Keys
A database backup does not carry the key that opens your encrypted data. Export both keys, restore one from its file, and see why the password matters.
Distance Between Two Points on the Earth With the geography Type
The distance between two points on the earth takes one method call once you store the points as a geography value. This post builds a small table of five US cities, turns latitude and longitude into points, and measures with STDistance in meters, kilometers and miles. It also compares the answer with a flat map formula and a sphere formula, and shows the error for swapped arguments.
NTILE Groups: How Uneven Rows and Ties Land in Each Tile
NTILE groups your sorted rows into the tiles you ask for, but the groups aren’t always the same size. This post uses ten hiking trails to show the sizes when rows do not divide evenly, how tied rows land in different tiles, and what happens with more tiles than rows. It also shows how to pull the top 2 percent of a list.
RANK( ), DENSE_RANK( ), and ROW_NUMBER( ): How Each Handles Ties
RANK( ), DENSE_RANK( ), and ROW_NUMBER( ) return the same numbers until your data has a tie. This post ranks eight teas with all three functions and shows how each one handles tied scores. It also shows how to list the top three distinct scores and why ROW_NUMBER needs a tiebreaker.
geometry STLength: A Path Is Longer Than Its Chord
geometry STLength measures the segments of a line. The example contrasts that path length with the shortest distance between its endpoints, including a closed line.
Partitioned Aggregates: Compare Each Row to Its Own Group
Partitioned aggregates let every row see a number for its own group, such as how many plants share its garden bed. This post uses thirteen seedlings in four beds to show PARTITION BY with COUNT and AVG. It also shows the integer division trap that turns every share into 0, and how to get one row per group.







