0% found this document useful (0 votes)
5 views3 pages

MySQL Teaching Manual

The document is a practical teaching manual for MySQL, detailing step-by-step instructions on various SQL operations using a 'customers' table. It covers basic SELECT queries, data manipulation (INSERT, UPDATE, DELETE), aggregate functions, GROUP BY and HAVING clauses, JOINS, VIEWS, stored procedures, triggers, transactions, and JSON column examples. Each section provides specific SQL commands and explanations for effective database management and querying.

Uploaded by

Faith Takefe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

MySQL Teaching Manual

The document is a practical teaching manual for MySQL, detailing step-by-step instructions on various SQL operations using a 'customers' table. It covers basic SELECT queries, data manipulation (INSERT, UPDATE, DELETE), aggregate functions, GROUP BY and HAVING clauses, JOINS, VIEWS, stored procedures, triggers, transactions, and JSON column examples. Each section provides specific SQL commands and explanations for effective database management and querying.

Uploaded by

Faith Takefe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

MySQL Practical Teaching Manual

Step-by-Step MySQL Practical Lesson Using customers Table

1. Basic SELECT Queries


------------------------
SELECT * FROM customers;
SELECT full_name, email, city FROM customers;
SELECT * FROM customers WHERE city = 'Lagos';
SELECT * FROM customers WHERE full_name LIKE 'J%';
SELECT * FROM customers ORDER BY account_balance DESC;
SELECT * FROM customers LIMIT 5;

2. INSERT, UPDATE, DELETE


--------------------------
INSERT INTO customers (...) VALUES (...);
UPDATE customers SET account_balance = account_balance + 1000
WHERE full_name = 'Jane Smith';
DELETE FROM customers WHERE full_name = 'John Doe';

3. Aggregate Functions
------------------------
SELECT COUNT(*) FROM customers;
SELECT AVG(account_balance) FROM customers;
SELECT MAX(account_balance) FROM customers;
4. GROUP BY and HAVING
------------------------
SELECT city, COUNT(*) FROM customers GROUP BY city;
SELECT city, AVG(account_balance) AS avg_balance FROM
customers GROUP BY city HAVING avg_balance > 10000;

5. JOINS (orders table required)


---------------------------------
SELECT c.full_name, o.order_amount, o.order_date FROM customers
c JOIN orders o ON c.customer_id = o.customer_id;

6. VIEWS
--------
CREATE VIEW high_value_customers AS SELECT full_name, email,
account_balance FROM customers WHERE account_balance >
10000;

7. STORED PROCEDURE
---------------------
CREATE PROCEDURE AddBonus(IN cust_id INT, IN bonus
DECIMAL(10,2)) ...
CALL AddBonus(2, 500.00);

8. TRIGGERS
------------
CREATE TRIGGER after_customer_update AFTER UPDATE ON
customers FOR EACH ROW BEGIN ... END;
9. TRANSACTIONS
----------------
START TRANSACTION;
UPDATE...; UPDATE...;
COMMIT;

10. JSON Column Example


------------------------
ALTER TABLE customers ADD preferences JSON;
UPDATE customers SET preferences = '{"newsletter": true}' WHERE
customer_id = 1;
SELECT * FROM customers WHERE JSON_EXTRACT(preferences,
'$.newsletter') = true;

You might also like