DeveloperBreeze

Sql Guide Development Tutorials, Guides & Insights

Unlock 2+ expert-curated sql guide tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your sql guide skills on DeveloperBreeze.

Managing Transactions and Concurrency in MySQL

Tutorial August 12, 2024
mysql

  • START TRANSACTION: Begins a new transaction.
  • COMMIT: Saves the changes made in the transaction permanently.
  • ROLLBACK: Reverts the changes made in the transaction.
START TRANSACTION;

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

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

COMMIT;

Viewing the Database Size and Identifying the Largest Table in MySQL

Tutorial August 12, 2024
mysql

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:

SELECT table_name AS "Table",
       ROUND((data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"
FROM information_schema.tables
WHERE table_schema = 'your_database_name'
ORDER BY (data_length + index_length) DESC
LIMIT 1;