From the course: Program Databases with Transact-SQL
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Create a transaction - SQL Server Tutorial
From the course: Program Databases with Transact-SQL
Create a transaction
- To explore how transactions work in SQL server, let's return to the colors table that we've worked with previously. In a prior movie, we created a stored procedure called USP Insert Color to help us enter new color names into that table. Now, if you've been following along, then you'll already have this stored procedure, but if not, you can run lines six through 16 in order to create it now. Okay. Let's turn our attention to transactions. In order to wrap a batch of commands into a transaction, we need to start the transaction at the beginning and end the transaction at the end. Starting a transaction is easy. Just run the begin transaction command, or you can abbreviate it to just simply Begin Tran. You can provide a name for the transaction, but that's optional. Naming your transactions can help you later on when it's time to close the transaction so that it's easy to see which lines correspond to which transaction name. I naming this transaction first transaction. If you do name…
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.