[MUSIC] Relational databases are the most common way of persistently storing data in a web application. Once again, by persistent I mean the data stored and you're able to persist it from one web session to the next. Examples of this type of data might be financial records, medical records, user information, account data, or are blog posts and comments. Here's the canonical web application architecture that we developed previously. Right now, we're going to focus on this portion of the architecture, the database backend. And we're going to assume it's a relational database. So let's talk a little bit more about relational databases so that I can introduce some terminology. As I've already mentioned, relational databases are commonly used in web apps, and a relational database stores collections of relations using tables, records, and attributes. Let's see how. Each row in a table, and sometimes a table's referred to as an entity, corresponds to one record, and the columns correspond to attributes or fields of that record. Here's an example. The name of the table is people, and each row corresponds to a record, except for the first row which lists the attributes. The attributes in this case are ID, first name, last name, address, and phone. The table is holding four records. And notice that there's an ID attribute associated with each record. Why do you think we need this attribute? The ID attribute is used to uniquely identify each record in the table. This is needed for other tables to refer to the records of this table. Did you notice that the name John Doe also appears twice in this table? Think about why. He appears twice because he has two phones. This illustrates a fundamental relationship in the data. Specifically, that there's a one-to-many relationship between people and phones. This relationship captures the notion that one person can have many phones, and we need to better model this in our database, too. Let's see how. The id attribute in the people table is called a primary key, and we can use this to form relationships with other tables. We've already said that there's a one-to-many relationship between people and phones, that is, that one person can have many phones. I'm going to show you how to normalize the database in order to account for this relationship. We'll do this by creating another table to hold phones. Database normalization is the process of reorganizing the attributes and tables of a relational database in order to reduce redundancies. Normalization usually involves dividing large tables into smaller tables, and defining relationships between them. You can do this by storing the primary key of a record as an attribute in another table where it's referred to as a foreign key. In this example the person ID will be stored in the phone table as a foreign key. Let me show you how this works graphically. Here's the original people table. We're going to remove the phone attribute from this table and store this information in a different table called the phone table. Notice the person ID attribute in the phone's table. In the first row of the phone's table, this attribute has the value of one. This means that it points to the row in the people table that has the primary key one. In the second row of the people table, the phone ID attribute is two. So it's pointing to John Doe in the people table. The fourth row of the phone's table also has the same person ID, so it's also pointing to John Doe. Notice how we reduced redundancy through normalization. John Doe is now only stored once in the people table and there is a row for each of his phones in the phone's table.