DeveloperBreeze

Sql Programming Tutorials, Guides & Best Practices

Explore 14+ expertly crafted sql tutorials, components, and code examples. Stay productive and build faster with proven implementation strategies and design patterns from DeveloperBreeze.

Managing Transactions and Concurrency in MySQL

Tutorial August 12, 2024
mysql

START TRANSACTION;

INSERT INTO accounts (user_id, balance) VALUES (1, 100);

UPDATE accounts SET balance = balance - 50 WHERE user_id = 1;

COMMIT;

In this example, two operations are performed within a transaction: inserting a new account and updating the balance. If any operation fails, you can use ROLLBACK to undo the changes.

Viewing the Database Size and Identifying the Largest Table in MySQL

Tutorial August 12, 2024
mysql

This query will output the size of the specified database in megabytes (MB).

To identify the largest table in terms of size within a specific database, use a similar query but without the grouping. Instead, order by size and limit the result to find the largest table: