Sql-Interview

SQL Interview: 43 No return value from calling procedure

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: Developer Level: Intro

Question:

You want to call a procedure that counts the number of customers in a particular city.

You use the following code:

DECLARE @NumberOfCustomers int;

EXEC dbo.GetNumberOfCustomers 
    @City = N'Brisbane', 
    @NumberOfCustomers = @NumberOfCustomers;

SELECT @NumberOfCustomers;

No matter which city name you pass in the code, the selected count is NULL.

2025-05-04

SQL Interview: 42 OPTION LABEL

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

Question:

You have a series of very similar SQL queries in an application.

You notice that one of them includes an OPTION LABEL clause.

What would this be used for?

Answer:

OPTION LABEL allows you to apply a label to an instance of a query. That then makes it easy to trace executions of the query using tools like Extended Events or SQL Server Profiler.

2025-05-02

SQL Interview: 41 Sparse columns vs Nullable columns

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

Question:

Your team is considering a design where a small number of tables would each have a very large number of columns.

One developer has suggested making the columns SPARSE where another has suggested just making them NULLable.

2025-04-28

SQL Interview: 40 Replacing text data type with varchar

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: Advanced

Question:

You have a table in your database that contains six columns that are defined with the text data type.

When you run checks on your database, these columns are often flagged with deprecation warnings, and so you change each column as follows:

2025-04-25

SQL Interview: 39 Char data types and row compression

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 have a column in your database that is defined as char(20). Whenever you query it, 20 characters are returned, with space padding any unused characters.

An administrator has suggested applying ROW compression to the table, to save space and improve performance.

2025-04-23

SQL Interview: 38 Table Compression Candidates

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:

A developer in your team has suggested applying PAGE compression to all tables and indexes in your application database.

You are concerned that doing so might impact performance, and that ROW compression might be better.

2025-04-19

SQL Interview: 37 DROP CREATE vs DISABLE REBUILD for SQL Server indexes

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: Advanced

Question:

You need to write code to avoid the impact of indexes during data loads.

You could DROP and CREATE the indexes, or you could DISABLE and REBUILD them.

Which should you choose and why? How would the performance compare between the two options?

2025-04-15

SQL Interview: 36 Dereferencing server names in T-SQL code

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 are using linked servers to refer to tables in a database on another server.

You are concerned that the name of the server appears in three-part table names throughout your code. If the linked server name changes, it would be very messy to locate and correct all references to it.

2025-04-13

SQL Interview: 35 T-SQL Merge Statement Clauses

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 are reading a T-SQL script. One MERGE statement merges data from TableA into TableB, and contains two clauses:

WHEN NOT MATCHED BY SOURCE

and

WHEN NOT MATCHED BY TARGET

What is the difference between these? And what is the most common operation that’s executed in each of these clauses?

2025-04-11

SQL Interview: 33 Physical Database Name in sys.databases

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 query the sys.databases view and notice that the value in the physical_database_name column for a database is different to the name column.

Can you give an example of why this might occur?

2025-04-04