From the course: Programming Foundations: Databases

Creating relationships

- Once we know which pieces of information we'll be storing in our database, we need to think about how those pieces of data are connected to each other. We thought about this a little bit when we were defining keys. Some databases can be used without connecting records in different tables at all. A database can simply retrieve records from one table or another table. But as we model more complex information in our database, we'll need to build relationships. There are three kinds of relationships to connect data. These are one-to-many relationships, many-to-many relationships, and one-to-one relationships. As I mentioned earlier, a relationship isn't something we have to define explicitly in our database schema, or in a DBMS tool. It can be more of a way of thinking about how pieces of data are connected to each other in our information model. When we're planning a database, we'll draw lines that represent relationships. And we'll use that information to create fields, organize tables, reduce redundancy, and improve the integrity of our data. And once the relationships are defined, we can configure our database to enforce them. In this chapter, we'll take a look at each relationship in turn, and see how they apply to our database.

Contents