From the course: Program Databases with Transact-SQL
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Automatically roll back transactions - SQL Server Tutorial
From the course: Program Databases with Transact-SQL
Automatically roll back transactions
- [Instructor] 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 line three through five, and I can see that the most recent color that we just added was color ID number 40, and it was lemon grass green. So let's go ahead and start a transaction. I'll run line number eight, and then I'm going to insert a new…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.