Search⌘ K
AI Features

Exercise: Transactions and Concurrency Control

Explore practical exercises that reinforce your understanding of transaction management and concurrency control. Learn to execute transactions involving insert, update, and rollback operations while maintaining data integrity. Verify changes and adjust transaction isolation levels to control database concurrency behavior effectively.

Let’s get some hands-on practice!

Question 1

Given the following structure of the Categories table:

Field

Type

CategoryID

int

CategoryName

varchar(50)

Where CategoryID is the primary key. The table contains information about categories of products.

Start a transaction, insert a new category named Office Supplies into the Categories table. Then, immediately roll back the transaction. Finally, verify that the Office Supplies category was not permanently added. 

MySQL 8.0
-- Demonstrating transaction rollback with an insert into the Categories table

If you’re stuck, click the “Show Solution” button.

Question 2

Given the following structure of the Customers table:

Field

Type

CustomerID

int

CustomerName

varchar(50)

Email

varchar(50)

Phone

varchar(15)

Address

varchar(100)

LastLogin

date

CreatedAt

timestamp

CustomerTier

enum('New','Regular','VIP')

ReferralID

int

LoyaltyPoints

int

LastPurchaseDate

date

IsChurnRisk

tinyint(1)

...