From the course: Complete Guide to Advanced SQL Server

Unlock the full course today

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

Solution: Create a transaction

Solution: Create a transaction

I hope you were able to create the stored procedure to transfer money from different bank accounts. Let's go ahead and walk through the solution. I have right now on the screen the 04_06_Challenge-Start.sql file. And let's just run through what this does real quick. It's going to drop a table if it exists. And that's the BankAccounts table. So if that table is already in your system for some reason, then we're going to drop it and then just recreate it again fresh. So we'll create the table "BankAccounts" and it's going to have two columns. AccountID will be an integer, and then we have our balance as a decimal (10,2) data type. Next, we're going to insert a couple of rows into the table, and then we'll select everything out of it just so we can see what our starting point is. So let's go ahead and just execute all of this. And here is our little table. So we've got our account ID. So Account 1 has $100, Account 2 has $200, and Account 3 has $300. So what we need to do here is…

Contents