Sql-Interview

SQL Interview: 55 Nested Transactions

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 code that uses transactions.

There is an outer transaction that contains an inner transaction.

If the inner transaction code executes a ROLLBACK, what is rolled back? Is it the inner transaction, the outer transaction, or both?

2025-06-13

SQL Interview: 54 Deadlock Correction

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

Question:

You have deployed a database application into production.

Soon after, you get reports that large numbers of deadlocks are occurring.

What is the most important first step in resolving deadlocks?

Answer:

While it might appear that looking into locking processes, etc. is critical, it is pointless reviewing these until you are certain that queries on the system are running efficiently.

2025-06-09

SQL Interview: 53 Dynamic SQL and Ownership Chaining

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

Question:

You have a table named Sales.Customers that is owned by dbo. You also have a stored procedure named Sales.FindCustomers that searches the Sales.Customers table.

A user Terry is given permission to the procedure and can successfully execute the procedure.

2025-06-05

SQL Interview: 52 Deleting duplicated rows

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:

You have an ETL process that loads employee details into a table named Staging.Employees. The table has the following columns:

  • EmployeeID (int)
  • FullName (nvarchar(100))
  • LoginName (varchar(100))

The table is a heap and has no primary key.

2025-06-01

SQL Interview: 51 Truncating datetime values to the minute

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 are creating a view in a SQL Server based data warehouse.

You need to query transactions that include a TransactionDateTime column which uses the DateTime data type. The query is as follows:

2025-05-28

SQL Interview: 50 Using WHERE vs HAVING

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 need to filter rows being returned by a query.

When should you use a HAVING clause rather than a WHERE clause?

Answer:

A WHERE clause is used to filter the rows from the source (usually a table).

2025-05-24

SQL Interview: 49 Index impacts on update operations

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:

You are considering adding an index to a table.

You have heard that adding indexes slows down UPDATE commands.

Does adding an index always slow down updates? If so, why? If not, why not?

2025-05-20

SQL Interview: 48 Enabling RCSI for a database

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 database application has been suffering from signficant blocking issues.

One developer has suggested enabling RCSI for the database.

If you do that, what’s different about how the database would operate?

What code changes are needed to use it?

2025-05-16

SQL Interview: 47 Extracting hour from a datetime value

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 need to extract the hour component from a datetime value.

Which function should you use?

Answer:

To do this in SQL Server, you should use the DATEPART function.

2025-05-12

SQL Interview: 46 Self-join requirements

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 have a table named HumanResources.Employees. Some employees are managers.

You want to join the table to itself to join employee rows with their manager rows.

What is required when you join a table to itself, that is not required for joining separate tables?

2025-05-10