Concept + worked examples + solved problems + exam-style MCQs. Porlei Silberschatz DBMS er selected chapter cover hoye jabe — boi ulto-palte porte hobe na.
Database holo connected data er ekta organized collection. Relational model e sob data table (relation) akare thake — row ar column diye.
| Term | Mane ki | Example |
|---|---|---|
| Relation | Ekta table | Student table |
| Tuple | Ekta row / record | ek jon student er info |
| Attribute | Ekta column | name, roll |
| Domain | Attribute er allowed value set | age → 0–150 integer |
| Degree | Column er sonkha | 4 column → degree 4 |
| Cardinality | Row er sonkha | 50 row → cardinality 50 |
Je attribute (ba set of attributes) diye ekta row unique kore identify kora jay. Eta unique kintu extra attribute thakte pare.
Minimal super key — jeta theke kono attribute bad dile r unique thake na. Ekta table e ekadhik candidate key thakte pare.
Candidate key gula theke bachai kora ekta key, ja main identifier hoy. NULL hote pare na, duplicate hote pare na.
Ek table er attribute ja onno table er primary key ke reference kore — eta diye relationship toiri hoy.
Ekadhik attribute mile toiri primary key (ekta column eka unique kore na).
Enroll(student_id, course_id, semester, grade) e ekjon student ekta course ekbar-i nite pare per semester. Primary key ki?
Ekjon student ek course ekbar nite pare per semester — mane same student same course different semester e nite pare. Tai shudhu student_id ba shudhu course_id unique noy.
Unique kore identify korte lage tinta mile: (student_id, course_id, semester).
Answer: Composite primary key = (student_id, course_id, semester). grade ekta non-key attribute (eta key er upor depend kore).
A eka unique kore → A super key. AB-o super key kintu A bad dile B chole na... ar A eka choley. Tai AB minimal noy (B extra).
Minimal super key = jeta theke kichu bad dile r unique thake na. A theke kichu bad dewa jay na (already single). Tai A i candidate key.
Answer: Candidate key = {A}. AB shudhu ekta super key (minimal noy).
SQL = Structured Query Language. Admission e tomake query likhte bola hote pare, ar output bolte bola hote pare. Niche sob clause example soho.
| Employee | |||
|---|---|---|---|
| emp_id | name | dept | salary |
| 1 | Rahim | CSE | 50000 |
| 2 | Karim | EEE | 45000 |
| 3 | Sadia | CSE | 60000 |
| 4 | Nabila | CSE | 55000 |
| 5 | Tania | EEE | 48000 |
-- CSE dept er sob employee
SELECT name, salary
FROM Employee
WHERE dept = 'CSE';
Output: Rahim/50000, Sadia/60000, Nabila/55000.
SELECT name, salary FROM Employee
ORDER BY salary DESC; -- DESC = boro theke choto
COUNT(), SUM(), AVG(), MAX(), MIN()
SELECT AVG(salary) FROM Employee; -- sob er average
SELECT MAX(salary) FROM Employee WHERE dept='EEE';
-- Prottek dept er average salary, jegula 50000+
SELECT dept, AVG(salary) AS avg_sal
FROM Employee
GROUP BY dept
HAVING AVG(salary) > 50000;
CSE avg = (50000+60000+55000)/3 = 55000 ✓ | EEE avg = (45000+48000)/2 = 46500 ✗. Output: shudhu CSE.
| Join type | Ki dey |
|---|---|
| INNER JOIN | Dui table er matching row matro |
| LEFT (OUTER) JOIN | Left table er sob + right er matching (na thakle NULL) |
| RIGHT JOIN | Right table er sob + left er matching |
| FULL OUTER JOIN | Dui table er sob row |
| CROSS JOIN | Cartesian product (m × n row) |
SELECT e.name, d.dept_name
FROM Employee e
INNER JOIN Department d ON e.dept = d.dept_code;
-- Average er beshi salary jara pay
SELECT name, salary FROM Employee
WHERE salary > (SELECT AVG(salary) FROM Employee);
AVG = (50000+45000+60000+55000+48000)/5 = 51600. Output: Sadia(60000), Nabila(55000).
SELECT dept, MAX(salary) AS max_sal
FROM Employee
GROUP BY dept
HAVING MAX(salary) > 50000;
CSE max = 60000 ✓, EEE max = 48000 ✗. Output: CSE / 60000.
Khoyal koro — aggregate (MAX) diye filter, tai HAVING, WHERE noy.
SELECT COUNT(*) ar COUNT(salary) er moddhe difference ki? Jodi ekta row e salary NULL thake?
COUNT(*) sob row gone — NULL soho. COUNT(salary) shudhu jegular salary NULL noy sheigula gone.
5 row, 1 tar salary NULL hole: COUNT(*) = 5, COUNT(salary) = 4.
Aggregate functions (SUM, AVG, COUNT(col)) NULL ke ignore kore — eta common MCQ trap.
NULL = NULL TRUE noy, eta UNKNOWN. NULL check korte IS NULL / IS NOT NULL use korte hoy, = NULL noy.Relational algebra holo SQL er theoretical bhitti — symbol diye query lekha. MCQ te symbol ar tar mane jiggesh kore.
| Operation | Symbol | Kaj |
|---|---|---|
| Select | σ (sigma) | Row filter (WHERE er moto) |
| Project | π (pi) | Column bachai (SELECT col) |
| Union | ∪ | Dui relation er sob row (duplicate baad) |
| Set Difference | − | R e ache kintu S e nei |
| Cartesian Product | × | Sob combination |
| Rename | ρ (rho) | Relation/attribute notun nam |
| Natural Join | ⋈ | Common attribute diye join |
| Intersection | ∩ | Dui tetei ache |
σ (salary > 50000) (Employee)
→ salary 50000 er beshi jara, sob column
π (name, dept) (Employee)
→ shudhu name ar dept column
π (name) ( σ (dept='CSE') (Employee) )
→ CSE dept er employee der name
SELECT name FROM Employee WHERE salary > 45000;
Age WHERE (row filter) = σ, tarpor SELECT column (project) = π.
πname ( σsalary > 45000 (Employee) )
Order matters likhte: select (σ) bhitore, project (π) bahire — efficient.
Cartesian product = prottek R row er sathe prottek S row. Tuple count = |R| × |S| = 4 × 3 = 12.
Ar column (degree) = R er degree + S er degree (jog hoy).
ER model diye database design kora hoy — bastob world ke entity ar relationship diye represent kora.
| Element | Diagram shape | Mane |
|---|---|---|
| Entity | Rectangle | Object (Student, Course) |
| Attribute | Ellipse | Property (name, age) |
| Relationship | Diamond | Entity gular sম্পর্ক (enrolls) |
| Key attribute | Underlined ellipse | Primary key (roll) |
| Multivalued attr | Double ellipse | phone numbers (ekadhik) |
| Derived attr | Dashed ellipse | age (DOB theke ber) |
| Weak entity | Double rectangle | Nijer key nei, parent lage |
Dui pasher-i "onek" → Many-to-Many (M:N).
Table: Student, Course, ar ekta junction table Takes(student_id, course_id) — total 3 ta table. Junction table er composite PK = (student_id, course_id), dutoi foreign key.
Strong entity: nijer primary key ache, eka thakte pare.
Weak entity: nijer puro primary key nei. Identify hote hole strong (owner) entity er upor depend kore. Eta "partial key" (discriminator) + owner er key mile identify hoy. Diagram e double rectangle, relationship double diamond.
Example: "Dependent" (employee er poribar) — employee chara identify kora jay na.
Normalization = table ke এমনভাবে design kora jate redundancy kome ar anomaly (insert/update/delete problem) na hoy. Ei topic admission e pakka ase.
X → Y mane: X jana thakle Y nirdharon hoy. Eg: roll → name (roll diye name pawa jay).
Prottek cell e ekta-i (atomic) value. Multivalued / repeating group thakbe na.
Eg: ek column e "Math, Physics" thakle — eta 1NF bhongo. Alada row korte hobe.
1NF + kono partial dependency nei. Mane non-prime attribute puro candidate key er upor depend korbe, ek angsher upor noy.
Shudhu composite key thakle 2NF niye chinta korte hoy. Single-attribute key hole automatically 2NF.
2NF + kono transitive dependency nei. Non-prime attribute onno non-prime attribute er upor depend korbe na.
3NF er kothin version. Prottek FD X → Y te X obossoi ekta super key hote hobe. 3NF allow kore jodi Y prime hoy, BCNF kore na.
R(StudentID, Course, Instructor). FD gula:StudentID, Course → InstructorInstructor → CourseCandidate key ber kori: (StudentID, Course) sob nirdharon kore → candidate key. Abar Instructor→Course thakay (StudentID, Instructor)-o ekta candidate key.
Prime attributes: StudentID, Course, Instructor (sob-i kono key er part!).
1NF: atomic value, ✓.
2NF: non-prime attribute nei (sob prime) → partial dependency er prosno-i othe na → 2NF ✓.
3NF: prottek FD te hoy LHS super key, noy RHS prime. Instructor→Course e Course prime ✓ → 3NF ✓.
BCNF: Instructor→Course e Instructor super key NOY → BCNF bhongo.
BCNF decomposition: R1(Instructor, Course), R2(StudentID, Instructor). Ekhon prottek FD er LHS super key.
Student(roll, name, dept, dept_head) e roll→name,dept ar dept→dept_head. Eta kon NF? Ki anomaly hobe?
Candidate key = roll (single). Tai 2NF ✓ (partial dependency er proshno nei)।
Kintu roll → dept → dept_head — eta transitive dependency (dept_head non-prime depend kore dept non-prime er upor)। Tai 3NF bhongo, table ekhono 2NF te ache.
Anomaly:
3NF decomposition: Student(roll, name, dept) + Dept(dept, dept_head).
R(A,B,C,D), candidate key AB, FD: AB→C, AB→D, C→D. Highest normal form ki?
Prime: A, B. Non-prime: C, D.
2NF: C,D ki AB er angsher upor depend kore? AB→C,D — puro key er upor, partial nei → 2NF ✓.
3NF: C→D dekho — C super key noy, ar D prime-o noy → transitive dependency. 3NF bhongo.
Answer: Highest NF = 2NF.
Transaction = ek ba ekadhik operation er logical unit ja "sob-i hobe noile kichu-i hobe na" niyom mene chole.
| Property | Mane |
|---|---|
| Atomicity | Pura transaction hobe, noile kichui na (all-or-nothing) |
| Consistency | Transaction er age-pore database valid state e thakbe |
| Isolation | Concurrent transaction eke onnoke disturb korbe na |
| Durability | Commit hole data permanent — power gele-o thakbe |
Active → Partially committed → Committed | (problem hole) → Failed → Aborted
Two-Phase Locking (2PL): dui phase — Growing (shudhu lock newa) ar Shrinking (shudhu lock chhara)। Ekbar lock chharle r notun lock newa jabe na. 2PL conflict-serializability nishchit kore.
Operation gular ek angsho holo (taka berolo) kintu baki angsho holo na (balance update holo na) — eta partial execution.
Atomicity eta thik kore: hoy puro transaction hobe, noile rollback kore kichui hobe na. Tai taka-o berobe na, ba berole abar fire ashbe.
Precedence graph (serialization graph) banano hoy — node = transaction, edge = conflict order (read-write/write-write same data).
Condition: graph e cycle na thakle schedule ti conflict serializable. Cycle thakle noy.
Eigula bhalo kore bujhe nao। Concept clear thakle MCQ e bhul hobe na।
Score nije track koro — kon topic e bhul hoy sheta abar oi tab e fire giye poro।
DBMS note shesh। Porer ta — Operating System (Scheduling + Memory + Deadlock) banai debo bolle। 💪