SQL queries to create indexes and foreign keys
When working in MySQL, we will often have multiple tables, containing multiple datasets. These datasets are often related to each other in some way, typically with a common field between them. For example, if we had a table of customers, each customer might have a customer ID. From here, we may have a table of orders that contains the customer ID of the person who ordered it. We can relate these two tables using the customer ID field that they both share.
This type of relationship is called a foreign key relationship. To help to define these relationships, MySQL allows us to specify them at the time of creating a table. This creates a relationship between the two tables. The main advantage of this is that we can enforce policies for the foreign keys. For example, suppose we wanted to change a customer ID in our customer table. It will, in turn, make sense that we want to update the same customer ID in every other table that it appears...