Sql-Server

SQL: What is Halloween protection?

If you’ve worked with SQL Server (or with databases in general) for any length of time, you will have heard someone refer to Halloween protection.  It refers to a problem where update operations could inadvertently end up modifying a row more than once.

Why halloween?

The name Halloween protection comes from when the problem occurred during research on the System R project at the IBM Almaden Research Center back in 1976.

2025-05-30

SSMS Tips and Tricks 1-11: Built-in standard reports

SQL Server Management Studio provides a large amount of information about databases by letting the user navigate around Object Explorer and view the properties of objects.

What I’m often surprized by though, is the number of users who haven’t ever explored the reports that are available. In another section, we’ll look at creating custom reports, but there is a wonderful set of built-in standard reports that you should explore. For example, if I right-click the WideWorldImporters database, I can see these reports:

2025-05-29

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

SSMS Tips and Tricks 1-10: Dependency Tracking

In early versions of SQL Server, the only way to try to track dependencies between tables, procedures, functions, etc. was to use the sp_depends stored procedure.

And everyone thought it lied.

The real problem was that it didn’t understand partial dependencies and deferred resolution of objects. For example, it got confused if you created a procedure that mentioned a table, then later created the table.

SQL Server 2012 introduced far superior dependency views, and SQL Server Management Studio (SSMS) shows dependencies using those views under the covers.

2025-05-27

SSMS Tips and Tricks 1-9: Turn off option to prevent saving changes that require table recreation

I don’t use the table designer in SQL Server Management Studio. Sorry, but I just don’t like it, or the options that it chooses for me. I’d rather use T-SQL every time, but I’m also the first to admit that there are plenty of people who would use that designer.

And when they do, many run into an error that says:

Saving changes is not permitted. The changes that you have made require the following tables to be dropped and re-created. You have either made changes to a table that can’t be re-created or enabled the option Prevent saving changes that require the table to be re-created.

2025-05-25

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

SSMS Tips and Tricks 1-8: Generate insert scripts that script data

Over the years, I’ve had a surprising number of questions on how to output all the data in a table as a series of INSERT statements. SQL Server Management Studio has had the ability to do this for a long time. Here’s an example.

In Object Explorer, I’ve expanded the WideWorldImporters database, then expanded Tables. Where people come unstuck is they right-click the table, and look at the scripting options:

2025-05-23

SQL: Are your linked servers secure?

I recently wrote about the most common misconfiguration that I see for linked servers. It greatly affects performance.

The second most common linked server misconfiguration is related to security. I can’t tell you how many times I’ve seen this when reviewing SQL Server systems for clients.

The issue you need to consider is that when your local SQL Server connects to the remote SQL Server, which identity is used for the connection?

2025-05-22

SSMS Tips and Tricks 1-7: Navigate as you type in sorted Object Explorer Details pane

I’ve mentioned a number of times how useful I think the Object Explorer Details panel is in SQL Server Management Studio.

One option in that panel that might not be so obvious is the sorted navigation. Here’s an example.

I’ve opened the WideWorldImporters database in Object Explorer, and clicked on the Tables node:

I then hit F7 to open the Object Explorer Details pane and clicked the Name heading to sort the table list. I like it ascending so you might need to click it twice:

2025-05-21

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