A relational database is a type of database that organizes data into tables.
These tables can be connected through relationships using common columns, such as IDs.
In simple words:
A relational database stores data in tables and allows related tables to be connected.
Consider a university database with a table named students.
| student_id | student_name | department_id |
|---|---|---|
| 101 | Ali | 1 |
| 102 | Ahmed | 2 |
| 103 | Sara | 1 |
| 104 | Ayesha | 3 |
Another table stores department information.
| department_id | department_name |
|---|---|
| 1 | Computer Science |
| 2 | Mathematics |
| 3 | English |
The department_id column is used to connect the two tables.
For example:
Instead of repeating the complete department name in every student record, the database stores the department ID.
This makes it easier to organize related information.
A primary key is a column or combination of columns that uniquely identifies each row in a table.
Example:
In the students table, student_id can be the primary key.
Each student must have a unique ID.
A foreign key is a column or combination of columns that refers to a primary key or other unique key in another table.
Example:
The department_id column in the students table can be a foreign key referencing department_id in the departments table.
One record in one table is associated with one record in another table.
Example: One person and one passport record.
One record in one table can be associated with multiple records in another table.
Example: One department can have many students.
Multiple records in one table can be associated with multiple records in another table.
Example: Many students can enroll in many courses.
A junction table is commonly used to represent a many-to-many relationship.