Database Fundamentals
Source: Dev.to
Why Data Is Important
What Are Databases?
What Makes a Good Database?
Different Types of Databases
Relational Databases Explained
What Is DBMS?
What Does DBMS Do?
Understanding Database Keys
Relationships Between Data
Problems with Databases
A Simple Analogy
Think of a database as a smart filing cabinet that stores information in an organized way.
Simple Definition:
A database is a place where we keep related information together so everyone in a company can use it easily.
Core Benefits
1. Store Lots of Information
Instead of keeping data in many Excel files or paper documents, you can put everything in one place and easily search for what you need.
2. Analyze Your Data
Ask questions like “How many customers bought products last month?” and get answers quickly. Create reports to understand your business better.
3. Keep Track of Records
Need to remember who paid you, what items are in your store, or customer phone numbers? A database keeps all this safe and organized.
4. Run Websites and Apps
Every time you use Facebook, Amazon, or any app, a database works behind the scenes to show you the right information.
5. Everyday Notebook Analogy
Imagine you have a notebook where you write:
- Names of your friends
- Their phone numbers
- Their birthdays
A database is like that notebook, but on a computer: it’s organized, searchable in a flash, and many people can use it at the same time.
5 Essential Qualities of a Good Database
| # | Quality | What It Means |
|---|---|---|
| 1 | Integrity (Correctness) | Information must be accurate (e.g., age = 25, not 250). |
| 2 | Availability (Always Ready) | Data should be accessible whenever you need it – 24/7. |
| 3 | Security (Protected) | Only authorized people can see or change the data. |
| 4 | Independent of Application (Flexible) | Works with any program (like a USB drive works with any computer). |
| 5 | Concurrency (Multi‑user) | Many users can access the data simultaneously without conflicts. |
Types of Databases
Just like there are different vehicles (car, bike, truck) for different needs, there are different types of databases.
| Type | Description | Typical Use‑Cases | Examples |
|---|---|---|---|
| Relational Databases (SQL) | Tables with rows & columns, similar to Excel spreadsheets. | Most common applications. | MySQL, PostgreSQL, Oracle |
| NoSQL Databases | Store “messy” data such as photos, videos, social‑media posts, documents. | Big data, flexible schemas. | MongoDB (used by Uber, eBay) |
| Column Databases | Store data column‑by‑column rather than row‑by‑row; great for analytics on huge datasets. | Data warehousing, analytics. | Google BigQuery, Amazon Redshift |
| Graph Databases | Model relationships between entities (e.g., friends on Facebook, recommendations on Netflix). | Social networks, recommendation engines. | Neo4j, Amazon Neptune |
| Key‑Value Databases | Simple dictionary‑style storage: a key maps to a value. | Caching, session storage. | Redis, DynamoDB |
Which one to pick?
It depends on what you’re building. For most beginner projects, start with a Relational Database.
Relational Databases – A Deeper Look
Think of a relational database as multiple Excel sheets that are related to each other.
| Sheet | Content |
|---|---|
| Sheet 1 | Student names and their ID numbers |
| Sheet 2 | Class names and which students are in them |
Both sheets use student IDs, so they are related.
How It Maps to Database Terms
- Tables = Excel sheets
- Rows = Each line of information (e.g., one student)
- Columns = Types of information (e.g., name, age, email)
DBMS – Database Management System
Analogy:
- Database = Library (where books are stored)
- DBMS = Librarian (helps you find, add, or remove books)
Popular DBMS Software
- MySQL
- PostgreSQL
- Oracle
- Microsoft SQL Server
What a DBMS Does
- Data Management – Save, retrieve, and modify information.
- Keeps Data Accurate (Integrity) – Prevents invalid entries (e.g., “ABC” as an age).
- Multi‑user Access (Concurrency) – Allows many users to work simultaneously without conflicts.
- Transactions – Guarantees operations are all‑or‑nothing (e.g., money transfers).
- Security – Enforces authentication and authorization.
- Utilities – Backup, import/export, user management, etc.
Keys – Identifying Data
A key is a unique identifier for each piece of information in a table.
| Key Type | Definition | Example |
|---|---|---|
| Super Key | Any combination of columns that uniquely identifies a row. | RollNumber + Name |
| Candidate Key | Minimal set of columns that can uniquely identify a row. | RollNumber |
| Primary Key ⭐ | The chosen candidate key; the main identifier for a table. | RollNumber (must be unique, not null, only one per table) |
| Alternate Key | Other candidate keys not selected as the primary key. | Email (if RollNumber is primary) |
| Composite Key | Two or more columns together uniquely identify a row. | Class + SeatNumber |
| Surrogate Key | Artificial identifier generated when no natural key exists. | Auto‑generated IDs like CUST001, CUST002 |
| Foreign Key | A key from another table used to create a relationship between tables. | StudentID in an Enrollments table referencing Students table |
Real‑Life Analogy
- Key: Your Aadhaar card number – unique to you.
- Super Key: Aadhaar + Phone + Email (any combination that’s unique).
- Candidate Key: Aadhaar alone (the smallest unique identifier).
- Primary Key: The Aadhaar number you decide to use as the main ID.
Summary
- Databases store, organize, and protect data so it can be accessed efficiently, analyzed, and shared across applications and users.