Hamburger Icon
  • Labs icon Lab
  • Data
Labs

SQL Fundamentals: Handling Transactions

In this lab, you'll learn how to create and execute SQL stored procedures and perform various data manipulation tasks. You'll practice building stored procedures for inserting and updating records, calling them with dynamic parameters, and using SQL functions such as CONCAT() and TIMESTAMPDIFF() to process and transform data. By the end of this lab, you'll be able to implement stored procedures to automate repetitive operations and manage data efficiently in a MySQL environment.

Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 58m
Published
Clock icon Nov 22, 2024

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Introduction to Transactions

    SQL Guide

    For each task, replace or update the existing SQL code in the top pane (main.sql) with your answer to the task and run it to see the results in the bottom pane (SQL Viewer).

    Step 1: Introduction to Transactions

    In this step, you will explore the basics of transactions and how they help maintain data integrity by grouping multiple SQL operations into a single unit of work. You will learn how to start a transaction, commit the changes, or roll back the transaction to undo all changes. By the end of this step, you will understand how transactions work in SQL and be able to apply them to manage data changes effectively.

    🫙 Database Structure

    Tables You Will Be Working With:

    Orders:

    | Column Name | Data Type | |--------------|--------------------------------| | OrderID | INT PRIMARY KEY AUTO_INCREMENT | | CustomerID | INT | | OrderDate | TIMESTAMP | | TotalAmount | DECIMAL(10, 2) | | Status | VARCHAR(20) |


    OrderItems:

    | Column Name | Data Type | |---------------|--------------------------------| | OrderItemID | INT PRIMARY KEY AUTO_INCREMENT | | OrderID | INT | | ProductID | INT | | Quantity | INT | | Price | DECIMAL(10, 2) |


    Products:

    | Column Name | Data Type | |-----------------|--------------------------------| | ProductID | INT PRIMARY KEY AUTO_INCREMENT | | ProductName | VARCHAR(100) | | ProductDescription | TEXT | | Price | DECIMAL(10, 2) | | StockQuantity | INT |

  2. Challenge

    Advanced Transaction Management

    Step 2: Advanced Transaction Management

    In this step, you will explore more advanced transaction management concepts, such as handling multiple operations within a single transaction and rolling back changes in the event of an error. You will learn how to perform updates, inserts, and condition checks across multiple tables and roll back or commit the changes. By the end of this step, you will understand how to manage more complex data operations within a single transaction block, ensuring data consistency.

    🫙 Database Structure

    Tables You Will Be Working With:

    Orders:

    | Column Name | Data Type | |--------------|--------------------------------| | OrderID | INT PRIMARY KEY AUTO_INCREMENT | | CustomerID | INT | | OrderDate | TIMESTAMP | | TotalAmount | DECIMAL(10, 2) | | Status | VARCHAR(20) |


    OrderItems:

    | Column Name | Data Type | |---------------|--------------------------------| | OrderItemID | INT PRIMARY KEY AUTO_INCREMENT | | OrderID | INT | | ProductID | INT | | Quantity | INT | | Price | DECIMAL(10, 2) |


    Products:

    | Column Name | Data Type | |-----------------|--------------------------------| | ProductID | INT PRIMARY KEY AUTO_INCREMENT | | ProductName | VARCHAR(100) | | ProductDescription | TEXT | | Price | DECIMAL(10, 2) | | StockQuantity | INT |


    Sales:

    | Column Name | Data Type | |-----------------|--------------------------------| | SaleID | INT PRIMARY KEY AUTO_INCREMENT | | ProductID | INT | | QuantitySold | INT | | SaleDate | TIMESTAMP | | TotalPrice | DECIMAL(10, 2) |

  3. Challenge

    Concurrency Control

    Step 3: Concurrency Control

    In this step, you will explore advanced SQL techniques for managing concurrency in multi-user environments. You will learn about row-level locking, optimistic concurrency control, and how to detect and resolve deadlocks. These concepts are essential for preventing data conflicts when multiple users or processes are accessing and modifying the same data simultaneously. By the end of this step, you will be able to manage concurrent data operations and prevent conflicts in a multi-user environment.

    🫙 Database Structure

    Tables You Will Be Working With:

    Customers:

    | Column Name | Data Type | |---------------|--------------------------------| | CustomerID | INT PRIMARY KEY AUTO_INCREMENT | | FirstName | VARCHAR(50) | | LastName | VARCHAR(50) | | Email | VARCHAR(100) | | PhoneNumber | VARCHAR(20) | | Address | VARCHAR(255) | | CreatedAt | TIMESTAMP |


    Orders:

    | Column Name | Data Type | |--------------|--------------------------------| | OrderID | INT PRIMARY KEY AUTO_INCREMENT | | CustomerID | INT | | OrderDate | TIMESTAMP | | TotalAmount | DECIMAL(10, 2) | | Status | VARCHAR(20) |

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.