Sql-Interview

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

SQL Interview: 32 Using ALTER FUNCTION in SQL Server

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 scalar T-SQL function in SQL Server and want to change it.

Apart from permissions, what would stop you from using ALTER FUNCTION to change it?

Answer:

You can’t change from an inline function to a multi-statement function.

2025-03-29

SQL Interview: 31 Create a copy of an Azure SQL Database on the same logical server

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

Question:

You have an Azure SQL Database.

How can you create a copy of the Azure SQL Database on the same logical server?

Answer:

The easiest option is to use the CREATE DATABASE AS COPY OF command.

2025-03-25

SQL Interview: 30 Temporary stored procedures in SQL Server

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:

Your session is connected to a database named PublicWorks.

You want to create a temporary stored procedure, that only lasts until your session has ended. It should be available to all other sessions while your session is still active.

2025-03-23

SQL Interview: 29 Add column to middle of SQL Server table

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 need to add a new column to a table.

A developer insists that the column needs to be inserted into the middle of the existing table, not as a new column at the end.

2025-03-21

SQL Interview: 28 When computed columns are calculated in SQL Server

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 add a computed column to an existing table.

You then select from the table.

When is the value of the computed column calculated i.e., when the value is inserted or updated, or when the value is selected?

2025-03-19

SQL Interview: 27 Copy only backups in SQL Server

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

Question:

You need to take an additional backup copy of a database to send to another site. You are considering using the Copy Only backup option.

What exactly is different about a Copy Only backup, compared to a Full backup?

2025-03-17

SQL Interview: 26 Whole of data operations when adding columns in SQL Server

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 need to add additional columns to a table. You are concerned that you do not want to lock the table for long periods. You plan to avoid any operation that would rewrite every row i.e., avoid whole of data operations.

2025-03-15

SQL Interview 25: Extended Stored Procedures in SQL Server

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 are reviewing stored procedures in the master database.

You note both Stored Procedures, and Extended Stored Procedures.

What is the difference between these types of procedures?

Answer:

Stored Procedures are written in T-SQL or SQL CLR and run in the standard user memory space of a SQL Server session.

2025-03-11