A foreign key is a field or group of fields in a table that uniquely identifies a row in another table. In other words, a foreign key is defined in a table that references to the primary key of the other table. It can be a proof for further comparison with the other output. It is Comparing with the description of the two tables after adding the foreign key constraint. Is a foreign key mandatory to make a. The common columns are typically the primary key columns of the first table and foreign key columns of the second table.
The behavior of foreign keys can be finely tuned to your application. Postgres: SQL to list table foreign keys. We will not go beyond this simple example in this tutorial, but just refer you to Chapter for more information. Making correct use of foreign keys will definitely improve the quality of your database applications, so you are strongly encouraged to learn about them.
Which one you prefer is a matter of taste. But you should be consistent in your scripts. As you may know, joins are used to combine data from two different tables. The way you combine them depends on the type of join you use.
There are a couple of key concepts to describe before we start JOINing data: Relationships. Secon because the (early days) table inheritance feature didn’t really support foreign keys either.
