Table of Contents
What is a Database?
A database is an organized collection of structured information, or data, typically stored electronically in a computer system. Think of it as a digital filing cabinet that can store, organize, and retrieve information efficiently.
Why Do We Need Databases?
- Data Organization: Keep information structured and accessible
- Data Integrity: Ensure data accuracy and consistency
- Concurrent Access: Multiple users can access data simultaneously
- Security: Control who can access what data
- Backup and Recovery: Protect against data loss
Types of Databases
1. Relational Databases (RDBMS)
Store data in tables with rows and columns. Examples: MySQL, MariaDB, PostgreSQL, Oracle.
Example Table: users
+----+----------+-------------------+
| id | username | email |
+----+----------+-------------------+
| 1 | john_doe | john@example.com |
| 2 | jane_doe | jane@example.com |
+----+----------+-------------------+
2. NoSQL Databases
Store data in flexible formats like documents, key-value pairs, or graphs. Examples: MongoDB, Redis, Cassandra.
Database Management System (DBMS)
Software that interacts with users, applications, and the database itself to capture and analyze data. Popular DBMS include:
- MariaDB/MySQL: Open-source relational database
- PostgreSQL: Advanced open-source database
- SQLite: Lightweight, file-based database
- Oracle: Enterprise-grade database system
Key Database Concepts
Tables
The basic structure for storing data, consisting of rows and columns.
Records (Rows)
Individual entries in a table representing a single item or entity.
Fields (Columns)
Attributes or properties of the data being stored.
Primary Key
A unique identifier for each record in a table.
Foreign Key
A field that links to the primary key of another table, creating relationships.
Real-World Example
Consider an online bookstore database:
Books Table:
+----+------------------+----------+-------+
| id | title | author | price |
+----+------------------+----------+-------+
| 1 | "The Great Gatsby"| F. Scott | 12.99 |
| 2 | "To Kill a Mockingbird" | Harper Lee | 14.99 |
+----+------------------+----------+-------+
Orders Table:
+----+---------+---------+----------+
| id | book_id | user_id | quantity |
+----+---------+---------+----------+
| 1 | 1 | 101 | 2 |
| 2 | 2 | 102 | 1 |
+----+---------+---------+----------+
Practice Exercise
Think about a simple library system. What tables would you need? What information would you store in each table? Consider:
- Books (title, author, ISBN, publication year)
- Members (name, email, membership number)
- Loans (which member borrowed which book, when)
Next Steps
In the next lesson, we'll dive into relational database design principles and learn how to structure data effectively using normalization techniques.