Introduction to DBMS
A database is an organised collection of data; a database management system (DBMS) is the software that stores, retrieves and protects it.
Why not plain files?
| File system | DBMS |
|---|---|
| Redundant, inconsistent copies | Controlled redundancy |
| Hard to query | Declarative queries (SQL) |
| No built-in concurrency control | Transactions and locking |
| Manual security | Fine-grained access control |
| Manual backup | Backup, recovery, logging |
Three-schema architecture
- External (views): what each user sees.
- Conceptual (logical): entities, relationships and constraints.
- Internal (physical): files, indexes, storage structures.
Data independence means a change at one level does not force changes at the next.
Entity-relationship (ER) model
| Concept | Meaning | Example |
|---|---|---|
| Entity | A real-world object | Student |
| Attribute | A property | name, roll_no |
| Relationship | Association between entities | Student enrolls in Course |
| Cardinality | 1:1, 1:N, M:N | One teacher teaches many courses |
A many-to-many relationship becomes its own table in the relational model:
enrollment.sql
CREATE TABLE enrollment (
student_id INT REFERENCES student(id),
course_id INT REFERENCES course(id),
grade CHAR(2),
PRIMARY KEY (student_id, course_id)
);
Types of databases
- Relational (PostgreSQL, MySQL): tables and SQL.
- Document (MongoDB), key-value (Redis), wide-column (Cassandra), graph (Neo4j).
Loading Comments...