π Day 91: Relational Databases
Welcome to Day 91! Today, we'll dive deep into the foundational concepts of Relational Databases.
What is a Relational Database?
A relational database is a type of database that stores and provides access to data points that are related to one another. Relational databases are based on the relational model, an intuitive, straightforward way of representing data in tables.
In a relational database, each row in the table is a record with a unique ID called the key. The columns of the table hold attributes of the data, and each record usually has a value for each attribute, making it easy to establish relationships among data points.
Key Concepts
Tables
- Definition: A table is a collection of related data held in a table format within a database. It consists of columns and rows.
- Example: A table named
employeesmight store information about the employees in a company.
Rows (Records)
- Definition: A row, also called a record, represents a single, implicitly structured data item in a table.
- Example: In the
employeestable, a row would represent a single employee.
Columns (Attributes)
- Definition: A column, also called an attribute, is a set of data values of a particular simple type, one for each row of the table.
- Example: In the
employeestable, columns might includeemployee_id,first_name,last_name, andhire_date.
Primary Key
- Definition: A primary key is a key in a relational database that is unique for each record. It is a unique identifier, such as a driver's license number, telephone number (including area code), or vehicle identification number (VIN). A relational database must always have one and only one primary key.
- Example: In the
employeestable,employee_idwould be the primary key.
Foreign Key
- Definition: A foreign key is a key used to link two tables together. It is a field (or collection of fields) in one table that refers to the PRIMARY KEY in another table.
- Example: If we have a
departmentstable with a primary keydepartment_id, we can add adepartment_idcolumn to ouremployeestable to specify which department each employee belongs to. Thisdepartment_idin theemployeestable is a foreign key.
Relationships
- One-to-One: Each record in one table is linked to one and only one record in another table.
- One-to-Many: A record in one table can be linked to many records in another table. (e.g., one department has many employees).
- Many-to-Many: Many records in one table are linked to many records in another table. (e.g., many students can be enrolled in many courses).
π» Exercises: Day 91
Please see the exercises.sql file for today's exercises.
Previous: Day 90 β Day 90 β Career Workshop and Next Steps β’ Next: Day 92 β Day 92: Data Definition Language (DDL)
You are on lesson 91 of 108.