In these lessons, you'll learn about different types of table relationships in SQL. In this lesson, we'll cover database normalization and the three primary types of relationships that exist in databases. This being one -to -one, one -to -many, and many -to -many. Database normalization is a process of organizing data in a database to avoid duplication, redundancy, and to improve data integrity. The goal of normalization is to divide a database into two or more tables and define the relationships between these tables to minimize data redundancy. Oftentimes, when designing a database, you want to create a diagram. For this lesson, I'll be using a tool on QuickDatabaseDiagrams .com, which is a free tool and allows us to map out our database. Now, for this tool, the syntax is slightly different than traditional SQL. We can still use the hashtag symbol to provide comments or but to list the name of the table, we simply just give it a name, followed by a dash on the next line. And from here, we list the names of our columns. So for our first column here, we'll be labeled student ID, the column data type, in this case an integer, as well as if there are any primary key or foreign key constraint. Also within the student table, we'll list their first name as a VARCHAR data type with up to 100 characters, as well as the student's last name that is also VARCHAR data type and up to 100 characters. Next, we'll be creating the student details table, which provides a little bit more detailed information about these students. This table will also contain a student ID of an integer data type. And for this rare case, it is a primary key and a foreign key. When using this tool to define our relationships, we list this here. In this case, this is a one to one. Then we list the relationship to the table, in this case, the student's table based on the student ID column. This column also contains the address, which is a VARCHAR data type of 100. And lastly, the city where the student resides, also a VARCHAR data type of 100 characters. So now let's get into one to one relationships. One to one relationships occur when one record in a table is associated with one and only one record in another table. So for this example, each student only has one student ID and each student ID is assigned to only one person. We see our relationship drawn here, where one student ID matches one student ID, which at the end of the day matches one person. In order to discuss one to many relationships, let's go ahead and build out a customers and orders table. So again, we define the customer's name. In this case, I've added an alias. First, we define the table name, which is customers. And in this scenario, I've added an alias of as C, which will make it shorter when we try to define our relationships. For this table, we have a customer ID of integer data type and a primary key. And again, we have a first name and a last name of VARCHAR data type up to 100 characters. Next, we'll define our orders table. And I'll give this an alias of O. The primary key for this table is the order ID and is of integer data type. We'll add a new column labeled order date and give this a date data type. And lastly, we also have the customer ID in this table, which is an integer as well as a foreign key constraint. This customer ID will link both of these tables together. Now, when defining our relationship here, rather than just having a dash, we have to have greater than sign or define the one to many. Here we're using the alias of C and listing the customer ID. You can see this reflective in our visualization with their customer ID to many customer IDs in the order ID column. All right, let's further break down one to many relationships. These are the most common types of relationships in SQL. In a one to many relationship, a record in one table and a multiple matching records in another table. So for this example, a single customer can place many orders, but an order can only belong to one and only one customer. Therefore, this relationship is defined by one customer being able to make many orders. Lastly, let's discuss many to many relationships. In order to do that, we're going to need to add a few more tables. We'll go ahead and create our products table alias SP. This table contains a product ID, which is an integer and the primary key for this table, as well as a product name, a bar chart data type, and up to 100 characters. Then we'll create an order details table and alias this as OD. For this table, the order ID as an integer data type and has a primary key as well as acts as a foreign key to the order ID in the orders table. When defining our relationship here, we have both greater than and less than signs with a dash in the middle to signify many to many. The same thing goes for the product ID column, which is an integer as well as a primary key and a foreign key constraint with the many to many relationship, the product ID in the products table. Last, we have the quantity column, which is an integer. Now that we have our tables, let's discuss many to many relationships in further detail. Many to many relationship is defined as when multiple records in a table are associated with multiple records in another table. So for this example, a single product can be in many orders and a single order can contain many products. To handle many to many relationships, we need to introduce what is called a junction or a bridge table. This table includes a primary key from each of the tables we're relating to. So in this example, our order details table would be our junction table since it links our orders and our products table together. When designing a database, it's essential to understand these types of relationships to define the logical structure of your data. Also, we won't be using this, but say in a real world scenario, we defined our schema and we want to export this. We simply click on the export here, list MySQL or whatever SQL provider you're using, and it will create all the create table statements as well as their relationships. This is a handy tool to speed up our database design process. Stay tuned for the next lesson where we write join queries to be able to retrieve data from multiple tables. Thanks for watching.