2.1 Relational Data Model
Key Concepts
1. Tables (Relations)
In the relational data model, data is organized into tables, also known as relations. Each table consists of rows and columns. Rows represent individual records or tuples, while columns represent attributes or fields. For example, a table named "Employees" might have columns like "EmployeeID," "Name," "Department," and "Salary." Each row in this table would represent a specific employee with their respective details.
2. Attributes
Attributes are the individual data fields within a table. Each attribute has a specific data type, such as integer, string, or date. Attributes define the structure of the data that can be stored in the table. For instance, in the "Employees" table, "EmployeeID" might be an integer, "Name" a string, and "Salary" a floating-point number.
3. Tuples
Tuples are the rows in a table, representing individual records. Each tuple contains a value for each attribute in the table. For example, a tuple in the "Employees" table might look like this: (101, "John Doe", "Sales", 50000.00). This tuple represents an employee named John Doe who works in the Sales department and earns $50,000 annually.
4. Keys
Keys are special attributes that uniquely identify tuples within a table. There are different types of keys:
- Primary Key: A primary key uniquely identifies each tuple in a table. For example, "EmployeeID" could be the primary key in the "Employees" table, ensuring that each employee has a unique identifier.
- Foreign Key: A foreign key is an attribute in one table that refers to the primary key in another table. This establishes a relationship between the two tables. For instance, a "DepartmentID" in the "Employees" table could be a foreign key that references the "DepartmentID" in a "Departments" table.
5. Relationships
Relationships define how tables are connected through keys. Common types of relationships include:
- One-to-One: Each record in one table is related to exactly one record in another table. For example, a "Passport" table might have a one-to-one relationship with a "Citizens" table, where each citizen has one passport.
- One-to-Many: Each record in one table can be related to multiple records in another table. For example, a "Departments" table might have a one-to-many relationship with an "Employees" table, where each department can have many employees.
- Many-to-Many: Multiple records in one table can be related to multiple records in another table. For example, a "Students" table might have a many-to-many relationship with a "Courses" table through a junction table "Enrollments," where each student can enroll in multiple courses, and each course can have multiple students.
Conclusion
The relational data model provides a structured way to organize and manage data using tables, attributes, tuples, keys, and relationships. Understanding these concepts is fundamental for designing efficient and scalable database systems that can handle complex data relationships and ensure data integrity.