From the course: Database Foundations: Database Management

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Commit and rollback transactions

Commit and rollback transactions

From the course: Database Foundations: Database Management

Start my 1-month free trial

Commit and rollback transactions

- [Narrator] A database transaction bundles a number of different commands into a single routine that either completes successfully or is entirely reversed. In order to create a transaction, we need to tell the server when the batch of commands is starting and when we've reached the end. The commands to do this are the same on both SQL server and PostgreSQL. And in fact, they're pretty standard across most RDBMS platforms. So you can follow along on either platform. I'm going to demonstrate on the PostgreSQL servers two-tree's database. Let's right click on it and choose new query. First, let's take a look at the current state of our categories table. We'll just select everything from that table. Now, right now we have three product categories. I want to add two more, but wrap the commands in the transaction so that the change is finalized in the database at the same time. To do this, we first need to open or start the transaction. We do this with a command begin transaction. This…

Contents