The Bit Bucket

SQL Interview 22: Working with Credentials in Azure SQL DB

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: Security Level: Medium

Question:

With SQL Server on-premises, you can create a CREDENTIAL and they are stored in the master database.

What option do you have with Azure SQL Database?

Answer:

You can create a DATABASE SCOPED CREDENTIAL in both SQL Server and in Azure SQL Database.

2025-02-21

T-SQL 101: 118 Creating Lists from Subqueries in SQL Server T-SQL

Another way that we can use a subquery is in place of a list of values. I’ve previously shown how the IN operator allows us to supply a set of values, and we check if something or some value is contained in that list.

In this example query, I’m saying that I want a list of all the cinemas that have a credit rating that isn’t OK. Perhaps it’s something to do with not paying their bills, or defaulted in some way.

2025-02-20

SDU Tools: SQL Server Type

Our free SDU Tools for developers and DBAs, now includes a very large number of tools, with procedures, functions, and views. A request that I had a while back was to have a function that returned what type of SQL Server the code was being executed on. So we added the SQLServerType function.

It takes no parameters.

As this is an enumerated value, it’s just a CASE statement.

Find out more

You can see it in action in the main image above, and in the video here. The full current version of the code is also shown below:

2025-02-19

T-SQL 101: 117 Creating Scalar Subqueries in SQL Server T-SQL

The first example of subqueries types in this series is what’s called a scalar subquery. In this case, I’m trying to work out which orders were on the last day that we delivered any orders. We deliver orders on various days, but on the last day that we did deliver orders, tell me which orders they were.

The problem with this is that we don’t know what the delivery date was. If I did, I could just use that date value in a WHERE clause. So what we can do instead is to use a subquery, where we work out the maximum delivery date from the orders table, and then that will return us back a date. Finally, we ask for all the orders for that particular day.

2025-02-18

SDU Tools: Last SQL Server Restart

Our free SDU Tools for developers and DBAs, now includes a very large number of tools, with procedures, functions, and views. A request that I had a while back was to have a function that returned the last time that SQL Server was restarted. So we added the LastSQLServerRestart function.

It takes no parameters.

I used to have a more complex way to work this out, but thanks to a great suggestion from our buddy Rob Wylie, it now just looks for the creation time of tempdb. That’s pretty good and simple to implement.

2025-02-17

T-SQL 101: 116 Using Subqueries in SQL Server T-SQL

Subqueries allow us to reuse data from one query in another query. There are three basic ways that this can work:

Row sets (tables) - a subquery can return an entire row set with columns. The basic structure of that is shown in the example above.

Lists - a type of row set that has a single column. It’s often used with an IN clause.

Scalar values - a single value returned from a query i.e., one row with one column. These are often used in place of values in expressions or predicates.

2025-02-16

Cosmos Down Under show 14 with guest Patty Chow discussing the DocumentDB offering from the Cosmos DB team is now released!

The big week for Down Under podcasts continues. I really enjoyed recording another new Cosmos Down Under podcast this morning. It’s now edited and released.

Show 14 features product manager in the Azure Cosmos DB team Patty Chow.

Patty Chow specializes in open source. She leads the development and strategy for DocumentDB, the open-sourced engine powering vCore-based Azure Cosmos DB for MongoDB. And that’s the key focus for this episode.

2025-02-15

SQL Interview: 21: Using ISNULL vs COALESCE

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:

When writing T-SQL code, you often need to replace NULL values. The core two functions provided are ISNULL and COALESCE.

What is the difference between them?

Answer:

ISNULL only takes a single value to check and replaces it when NULL.

2025-02-15

T-SQL 101: 115 Repetitively selecting with CROSS APPLY, OUTER APPLY

We saw in previous post that we had a function called GetRecentOrders that gets the most recent orders for a particular cinema.

But what if we want to do that for all the cinemas?

If I’d like the two most recent orders for every cinema, that becomes messy. I can’t just do that with a join, like an inner join or outer join. The function provided is fine. We can use that, but we want to call it for every row in the table.

2025-02-14

SDU Tools: List Constraints with System Names in SQL Server

Our free SDU Tools for developers and DBAs, now includes a very large number of tools, with procedures, functions, and views. I do a lot of reviewing of database designs and one of my least favourite things to see is the use of default system names for constraints. So we added a tool that can help to find when this has happened. It’s called ListConstraintsWithSystemNames.

The procedure takes three parameters.

2025-02-13