■ Day 1 – Databases & SQL Basics
1. What is DBMS?
• DBMS (Database Management System): Software to store, organize, and manage data.
• RDBMS (Relational DBMS): Uses tables (rows & columns). Example: MySQL, PostgreSQL.
• NoSQL: Works with documents, key-value, graph data. Example: MongoDB.
• Why DBMS? Avoids data redundancy, ensures consistency, provides security & backup,
enables multi-user access.
2. Keys in Database
• Primary Key: Uniquely identifies a record (e.g., student_id).
• Foreign Key: Refers to primary key in another table (creates relation).
• Candidate Key: Possible choices for primary key.
• Composite Key: Two or more attributes combined to uniquely identify.
3. ER Model Basics
• Entity: Object in database (e.g., Student, Course).
• Attribute: Property of entity (e.g., Name, Age).
• Relationship: Connection between entities (e.g., Student enrolls in Course).
4. SQL Basics
• CREATE TABLE Students (student_id INT PRIMARY KEY, name VARCHAR(50), age INT);
• INSERT INTO Students VALUES (1, 'Ali', 20);
• INSERT INTO Students VALUES (2, 'Sara', 22);
• SELECT * FROM Students;
• SELECT name FROM Students WHERE age > 20;
• UPDATE Students SET age = 23 WHERE student_id = 2;
• DELETE FROM Students WHERE student_id = 1;
5. Filtering & Grouping
• SELECT age, COUNT(*) FROM Students GROUP BY age HAVING COUNT(*) > 1;
• WHERE → row-level filter
• GROUP BY → groups rows
• HAVING → filter groups
6. Joins
• INNER JOIN: Returns matching rows.
• LEFT JOIN: All from left + matching right.
• RIGHT JOIN: All from right + matching left.
• FULL JOIN: All rows from both.
• Example: SELECT [Link], c.course_name FROM Students s INNER JOIN Courses c ON
s.student_id = c.student_id;
7. Normalization
• 1NF: Atomic values (no repeating groups).
• 2NF: 1NF + no partial dependency.
• 3NF: 2NF + no transitive dependency.