The Bit Bucket

Cosmos Down Under show 13 with guest Rakhi Thejraj discussing auto-scaling in Cosmos DB is released

Cosmos Down Under show 13 with guest Rakhi Thejraj discussing auto-scaling in Cosmos DB is released

It’s been yet another big week for Down Under podcasts. I really enjoyed recording another new Cosmos Down Under podcast this afternoon. It’s now edited and released.

Show 13 features product group member Rakhi Thejraj.

Rakhi is one of the Cosmos DB product managers and is involved in supporting the elasticity, and ingestion features, plus security initiatives and AI customer reach outs.

I took this opportunity to discuss throughput provisioning and auto-scaling with her.

2025-02-06

SQL Interview: 18: Table Truncation and Foreign Keys

SQL Interview: 18: Table Truncation and Foreign Keys

This is a post in the SQL Interview series. These aren’t trick or gotcha questions, they’re just questions designed to scope out a candidate’s knowledge around SQL Server and Azure SQL Database.

Section: Administration Level: Medium

Question:

You have two tables:

  • dbo.Customers
  • dbo.Orders

The dbo.Orders table has a column CustomerID that is declared as a foreign key to the CustomerID column in the dbo.Customers table. In the dbo.Customers table, CustomerID is the primary key.

2025-02-06

T-SQL 101: 110 Joins without equality (non-equi joins)

T-SQL 101: 110 Joins without equality (non-equi joins)

I’ve made several posts about joins but one option that I haven’t talked about as yet, are what are called non-equi joins.

These are less common, and they often don’t optimize all that well, but it’s worth noting that joins don’t always have to be on equality, or what are called equi-joins.

Non-equi join sounds complex but all we’re saying is that the things that we’re joining on are not equal signs.

2025-02-06

SQL Interview: 17: Using NULLIF

SQL Interview: 17: Using NULLIF

This is a post in the SQL Interview series. These aren’t trick or gotcha questions, they’re just questions designed to scope out a candidate’s knowledge around SQL Server and Azure SQL Database.

Section: Development Level: Medium

Question:

You see the following statement in a query that you are reviewing.

What is the purpose of the NULLIF function in this statement?

SELECT @a / NULLIF(@b, 0);

What was the author trying to achieve?

Answer:

The variable @a is being divided by the variable @b, but the variable @b might be zero. In that case, a divide by zero error would be returned.

2025-02-05

T-SQL 101: 109 Joining a table to itself (self joins)

T-SQL 101: 109 Joining a table to itself (self joins)

One thing you might not have considered is that a table can also be joined to itself.

Imagine that I want a list of employees, but I also want their manager’s details, the employee ID and the name for the manager. Now the problem is they’re both in the same table, but they’re different rows in that same table because a manager is also an employee.

The way I did this in the example is to say that I’m reading from Employees and then joining to Employees i.e. the same table.

2025-02-05

SQL Interview: 16: UNION and Column Aliases

SQL Interview: 16: UNION and Column Aliases

This is a post in the SQL Interview series. These aren’t trick or gotcha questions, they’re just questions designed to scope out a candidate’s knowledge around SQL Server and Azure SQL Database.

Section: Development Level: Intro

Question:

I execute the following query:

SELECT st.SalesTerritoryID AS [ID],
       st.SalesTerritoryName AS [Name],
       st.DateCreated
FROM dbo.SalesTerritories AS st

UNION

SELECT p.ProductID AS [Product],
       p.[Description],
       p.DateCreated AS [StartDate]
FROM dbo.Products AS p;

What alias will be returned for the each column in the returned results?

2025-02-04

T-SQL 101: 108 Joining more than two tables

T-SQL 101: 108 Joining more than two tables

Of course, you might also need to join more than two tables. The example above shows how to do that.

I started with the Orders table, then joined to the OrderLines table, and finally, I’ve also joined to Products.

It’s another example of why I prefer the modern join syntax. Instead of just listing three tables and a bunch of WHERE clause predicates, for each table involved, I specify how it’s joined.

2025-02-04

SDU Tools: Tools View

SDU Tools: Tools View

Our free SDU Tools for developers and DBAs, now includes a very large number of tools, with procedures, functions, and views. A while back, we added the ability to retrieve the version of the toolset programmatically, but an interesting request that we had, asked for the ability to query the toolset for the tools themselves. The Tools view now does that.

The view returns the following columns:

ToolName ToolTypeCode ToolType Category Description VideoURL

2025-02-03

T-SQL 101: 107 Using other outer joins with RIGHT OUTER JOIN, FULL OUTER JOIN

T-SQL 101: 107 Using other outer joins with RIGHT OUTER JOIN, FULL OUTER JOIN

After discussing LEFT OUTER JOIN, you might wonder if there is also a RIGHT OUTER JOIN. There is, and it’s the reverse of the left one.

What a RIGHT OUTER JOIN from Products to ProductGroups says is that I want at least one row for every row in ProductGroups. You can see that in the query example above. The product group Hot Food currently has no products in it. The RIGHT OUTER JOIN causes it to be returned, as similar to what happens with a LEFT OUTER JOIN, the columns from the non-matching table are returned as NULL. In this example, the product description for that group is returned as NULL.

2025-02-03

SDU Tools: Calculate Age in Months

SDU Tools: Calculate Age in Months

Another request that I received a while back, for a new function in our free SDU Tools for developers and DBAs, was to be able to find someone’s age in months. The same would apply to anything where the distance between two dates needs to be measured in months. In response, we added a new function CalculateAgeInMonths.

It takes two parameters:

@StartingDate date - the date to calculate from (could be a birth date if it’s an age) @CalculationDate date - the date to calculate the age to

2025-02-02