jorgepinho;10988361 wrote:
A foreign key (FK) states that this field is a primary key in another table.
Not true. It states that the value of the field(s) defined as a foreign key must exist in the table it refers to. The referenced field(s) do not have to be the primary key or part thereof, but the referenced field(s) do have to constitute a candidate key.
jorgepinho;10988361 wrote:
It is not mandatory to have this PK-FK to join tables.
But there is absolutely no reason for not using FKs. Well, there possibly might be, but if that should be the case, such an example eludes me at the moment. Making use of FKs helps assure that you keep your database in a consistent state by enforcing the FK constraints.
Moreover, it also makes managing your database easier through the use of CASCADE, SET DEFAULT, SET NULL, RESTRICT, NO ACTION.
jorgepinho;10988361 wrote:
To JOIN tables you just "link" to fields that have the same meaning
Usually (since it makes sense) but there is no enforcement of this, most likely since the DB can't know what "having the same meaning" is. But you can actually supply anything there, just like you can in the WHERE clause, including values of primitive types.
FROM firstTable ft
JOIN otherTable ot ON ot.someField = 3 AND ft.otherField = 'three'