From the course: Complete Guide to Advanced SQL Server

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Automatically roll back transactions

Automatically roll back transactions - SQL Server Tutorial

From the course: Complete Guide to Advanced SQL Server

Automatically roll back transactions

In the previous examples, we've manually chosen whether to commit or roll back a transaction, but we haven't yet looked at what happens when a transaction includes a command that generates an error. A common misconception about transactions is that they automatically revert the database to the state that it was in when an error is encountered. But that isn't always the case, and knowing what to look for can help you better understand what's happening on your system when you've implemented transactions. First, let's take a look at the default behavior of SQL Server. I'm going to stick with the Colors table again, and take a quick look at the contents to review the starting state of our data. I'll run the SELECT statement on Lines 3 through 5, and I can see that the most recent color that we just added was ColorID Number 40, and it was lemongrass green. So let's go ahead and start a transaction. I'll run Line Number 8. And then I'm going to insert a new color called burnished bronze…

Contents