Sql-Interview

SQL Interview: 78 SELECT *

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 use a tool that does static code analysis of your T-SQL code.

It identifies the following predicate as an issue:

WHERE EXISTS 
(
    SELECT * 
    FROM dbo.Products AS p 
    WHERE p.ProductID = c.ProductID
)

Is this an issue?

2025-09-13

SQL Interview: 77 SARGability

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:

A DBA at your site tells you that you need to make sure your predicates are sargable.

What is SARGability?

Assume a table has a column called OrderDate and it is of date data type. There is a single column index on the column. Can you give an example of a non-sargable predicate that uses it?

2025-09-09

SQL Interview: 76 Performance of temporary tables vs table variables

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:

Are there situations where temporary tables will perform better than table variables?

What could cause that?

Answer:

Temporary tables have two properties that are not available to table variables:

  • Indexes - with table variables, you can have primary key constraints and unique key constraints, but not other indexes
  • Statistics - temporary tables support rich statistics, similar to tables where table variables have very limited statistics, mostly just cardinality.

2025-09-05

SQL Interview: 75 Boolean logic with NULLs

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:

In the following WHERE clause, both AColumn and AnotherColumn are NULL.

WHERE AColumn = AnotherColumn

What is the effect of the WHERE clause?

Answer:

In SQL boolean logic, the expression NULL = NULL returns NULL and not True. So the WHERE clause would exclude the rows.

2025-09-01

SQL Interview: 74 Revoking permissions

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:

Is it possible that revoking a permission can cause a user to be able to access a resource, when they previously could not?

If so, how?

Answer:

REVOKE can remove either a GRANT or a DENY. Revoking a DENY can cause a user to be able to access a resource that they previously could not.

2025-08-28

SQL Interview: 73 Orphaned users

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:

In SQL Server, what is an orphaned user?

How do users typically become orphaned?

Answer:

An orphaned user is one that appears in a database, but the server principal that they are linked to, does not exist.

2025-08-24

SQL Interview: 72 Dynamic data masking and encryption

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:

Is dynamic data masking a form of encryption?

Answer:

No. Dynamic data masking just obfuscates the data when it is presented to end users. It is unrelated to encryption.

Obfuscation is not a form of encryption.

2025-08-20

SQL Interview: 71 Potential issues with NOLOCK

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 have applications that make extensive use of NOLOCK hints. You have heard that this can cause issues.

Which of the following issues could occur as a result of using NOLOCK hints?

  • Duplicate rows
  • Phantom rows
  • Missing rows

Answer:

2025-08-16

SQL Interview: 70 Updating statistics during index rebuilds

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:

When you rebuild indexes, are statistics on the table automatically rebuilt?

If not, why?

Answer:

Rebuilding indexes updates the statistics for the index, but column statistics are not updated unless they are tied to the index.

2025-08-12

SQL Interview: 69 When tempdb gets used

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 monitoring a SQL Server and you notice that tempdb is being heavily accessed. You know that your applications make very little use of temporary tables.

Can you give examples of other things that might be using tempdb.

2025-08-08