MySQL Notes
MySQL Notes
1. Introduction to MySQL
MySQL is an open-source relational database management system (RDBMS) that uses Structured
It is widely used for web applications and supports CRUD operations, multi-user access, and
scalability.
2. Data Types
- Numeric: INT, FLOAT, DECIMAL, etc.
7. Indexes
Indexes improve query performance.
8. Views
Views are virtual tables based on a SELECT query.
Example: CREATE VIEW user_orders AS SELECT u.name, o.order_id FROM users u JOIN orders
o ON u.id = o.user_id;
Example: CREATE PROCEDURE GetUser(IN userId INT) BEGIN SELECT * FROM users
Example: CREATE TRIGGER before_insert_users BEFORE INSERT ON users FOR EACH ROW
Example: CREATE TABLE orders (id INT PRIMARY KEY, user_id INT, FOREIGN KEY (user_id)
REFERENCES users(id));
11. Transactions
Transactions group multiple SQL commands into a single unit of work.
Example: START TRANSACTION; UPDATE users SET balance = balance - 100 WHERE id = 1;
COMMIT;