Types of Databases
INF2603 - Databases I · Introduction to Databases
Types of Databases
Databases can be classified into several types based on their structure, data model, and the way they are accessed. Understanding these types is essential for choosing the right database for a specific application.
1. Relational Databases
Relational databases are the most common type. They store data in tables, which consist of rows and columns. Each table represents an entity, and each row corresponds to a record. Columns represent attributes of the entity.
For example, consider a table named Students:
+----+----------+-----------+-----------+-----------+
| ID | Name | Surname | Age | Course |
+----+----------+-----------+-----------+-----------+
| 1 | John | Doe | 20 | Computer Science |
| 2 | Jane | Smith | 22 | Information Systems |
+----+----------+-----------+-----------+-----------+In this table, ID is the primary key, which uniquely identifies each record. You can perform operations like SELECT, INSERT, UPDATE, and DELETE using SQL (Structured Query Language).
Remember: In relational databases, relationships between tables are established using foreign keys.
2. NoSQL Databases
NoSQL databases are designed for unstructured data and can handle large volumes of data that do not fit well into tables. They are often used in big data applications and real-time web applications.
There are several types of NoSQL databases:
- Document Stores: These store data in documents, usually in JSON format. An example is MongoDB.
- Key-Value Stores: These store data as a collection of key-value pairs. An example is Redis.
- Column-Family Stores: These store data in columns rather than rows. An example is Apache Cassandra.
- Graph Databases: These are used to represent data with complex relationships, such as social networks. An example is Neo4j.
Watch out: NoSQL databases do not use SQL for querying. Each type has its own query language.
3. Object-Oriented Databases
Object-oriented databases store data in the form of objects, similar to object-oriented programming. Each object can contain both data and methods to manipulate that data.
For example, consider a class Student:
class Student {
int id;
String name;
String surname;
int age;
String course;
void displayInfo() {
// code to display student information
}
}In this case, a Student object would contain all the properties and methods related to a student. Object-oriented databases are useful for applications that require complex data representations.
4. Hierarchical Databases
Hierarchical databases organize data in a tree-like structure. Each record has a single parent and can have multiple children. This structure is useful for representing relationships where one entity is a parent to others.
An example of a hierarchical database is IBM's Information Management System (IMS). Consider a simple hierarchy:
Company
├── Department A└── Department B
└── Employee 3
In this example, the Company is the root, and it has two departments, each with its employees. The main limitation of hierarchical databases is that they do not support many-to-many relationships easily.
Remember: Hierarchical databases are not flexible; adding new relationships can be complex.
5. Network Databases
Network databases are similar to hierarchical databases but allow more complex relationships. In network databases, a record can have multiple parents. This structure is represented as a graph.
An example of a network database is Integrated Data Store (IDS). Consider a network structure:
Student
├── Course A└── Course B
└── Instructor 3
In this case, a student can be enrolled in multiple courses, and each course can have multiple instructors. Network databases provide more flexibility than hierarchical databases.
Watch out: Network databases can be complex to design due to their many-to-many relationships.
6. Distributed Databases
Distributed databases are spread across multiple locations, often across different servers or geographical locations. They allow for data to be stored closer to where it is used, improving access speed and reliability.
For example, a company might have a database server in Cape Town and another in Johannesburg. The data can be synchronised between these servers. This setup is beneficial for large organisations with multiple branches.
Tip: Distributed databases can improve performance but require careful management to ensure data consistency.
7. Cloud Databases
Cloud databases are hosted on cloud computing platforms. They can be relational or NoSQL and offer scalability and flexibility. Users can access cloud databases over the internet.
Examples include Amazon RDS (Relational Database Service) and Google Cloud Firestore (a NoSQL database). Cloud databases allow businesses to scale their database resources as needed without investing in physical hardware.
8. Data Warehouses
A data warehouse is a type of database designed for analytical purposes. It stores large volumes of historical data and is optimised for read access. Data warehouses are used for reporting and data analysis.
For example, a retail company might use a data warehouse to store sales data from the past five years to analyse trends. Data warehouses often use a star schema or snowflake schema to organise data.
Remember: Data warehouses are not designed for transaction processing; they are used for analysis and reporting.
9. Summary of Database Types
- Relational Databases: Store data in tables.
- NoSQL Databases: Handle unstructured data.
- Object-Oriented Databases: Store data as objects.
- Hierarchical Databases: Organise data in a tree structure.
- Network Databases: Allow complex relationships.
- Distributed Databases: Spread across multiple locations.
- Cloud Databases: Hosted on cloud platforms.
- Data Warehouses: Used for analytical purposes.
Check your understanding
- What is the main characteristic of a relational database?
- Give an example of a NoSQL database type and describe its use case.
- What are the limitations of hierarchical databases?
- How do cloud databases differ from traditional databases?