๐ง 1. What is DBMS (Database Management System)?
A DBMS is software that interacts with end-users, applications, and the database itself to capture and analyze data.
๐น Key Functions:
- Data storage, retrieval, and update
- User management and authentication
- Transaction management (ACID properties)
- Backup and recovery
- Data abstraction and security
๐น Examples:
- Relational DBMS: MySQL, PostgreSQL, Oracle
- NoSQL DBMS: MongoDB, Redis, Cassandra
๐ 2. SQL vs NoSQL Databases
Feature | SQL (Relational) | NoSQL (Non-Relational) |
---|---|---|
Data Format | Tables with rows and columns | Document, Key-Value, Graph, Column |
Schema | Fixed schema (structured) | Dynamic schema (flexible) |
Scalability | Vertical (add resources to one server) | Horizontal (add more servers) |
Examples | MySQL, PostgreSQL, Oracle | MongoDB, Firebase, Cassandra |
Query Language | SQL | No fixed language, uses JSON-style queries |
Best Use Case | Banking, ERP, structured data | Real-time apps, IoT, big data |
๐น Example:
- SQL:
SELECT * FROM users WHERE age > 30;
- NoSQL (MongoDB):
db.users.find({ age: { $gt: 30 } });
๐ฌ 3. Introduction to MySQL
MySQL is a popular open-source relational database based on SQL. It is widely used for:
- Web applications (e.g., WordPress)
- Data warehousing
- E-commerce and analytics
๐น MySQL Key Features:
- Supports transactions
- Foreign key constraints
- High performance and reliability
- Open-source with enterprise support
๐๏ธ 4. Database-Related Queries
๐น Create a Database
CREATE DATABASE mydb;
๐น Use a Database
USE mydb;
๐น Show Databases
SHOW DATABASES;
๐น Drop a Database
DROP DATABASE mydb;
๐ 5. Table-Related Queries
๐น Create Table
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100),
email VARCHAR(100) UNIQUE,
age INT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
๐น Alter Table
Add a Column:
ALTER TABLE users ADD gender VARCHAR(10);
Modify Column:
ALTER TABLE users MODIFY age SMALLINT;
Rename Column:
ALTER TABLE users CHANGE name full_name VARCHAR(100);
Drop Column:
ALTER TABLE users DROP COLUMN gender;
Rename Table:
RENAME TABLE users TO customers;
๐น Drop Table
DROP TABLE users;
๐น Describe Table Structure
DESCRIBE users;
๐ 6. SELECT (Basic Query)
๐น Select All Rows
SELECT * FROM users;
๐น Select Specific Columns
SELECT name, age FROM users;
๐น Where Condition
SELECT * FROM users WHERE age > 25;
๐น Order By
SELECT * FROM users ORDER BY age DESC;
๐น Limit Results
SELECT * FROM users LIMIT 5;
๐น Aliases
SELECT name AS full_name FROM users;
โ๏ธ 7. INSERT Query (Basic)
๐น Insert One Record
INSERT INTO users (name, email, age)
VALUES ('Suraj Kumar', 'suraj@example.com', 24);
๐น Insert Multiple Records
INSERT INTO users (name, email, age) VALUES
('Karan', 'karan@example.com', 28),
('Asha', 'asha@example.com', 32);
๐ง Bonus: UPDATE and DELETE
๐น Update Records
UPDATE users SET age = 25 WHERE name = 'Suraj Kumar';
๐น Delete Records
DELETE FROM users WHERE age < 20;
Written by
Suraj Kumar Jha
At
Tue Jul 15 2025