Tables (database and query results) represent application relationships.
From (earlier version) this answer :
For each base table, the database administrator provides a predicate, a natural language fill wording (named-) template, parameterized by column names.
-- chef with id NUMCUISINIER has name NOMCUIS and ... CUISINIER(NumCuisinier, NomCuis, ...)
The base table contains rows that, using the values ββof their columns, fill in (named) spaces, make a true statement as a sentence.
CUISINIER NumCuisinier | NomCuis | ... ---------------------------- 1 | DURAND | ... -- chef with id 1 has name 'DURAND' and ... ... -- AND for every absent row (NUMCUISINIER, NOMCUIS, ...), NOT (chef with id NUMCUISINIER has name NOMCUIS and ...)
Each SQL statement / statement converts the value of the old table to a new value containing strings that make a true statement from some new predicate that can be expressed in terms of the original predicate.
The predicate R JOIN S is the predicate R AND ed with the predicate S The predicate R ON/WHERE condition is the predicate R AND ed with condition .
/* rows where chef with id c.NUMCUISINIER has name c.NOMCUIS and ... AND kitchen with id a.NUMCUISINE ... AND c.NUMCUISINE = a.NUMCUISINE */ CUISINIER c join ATELIER_CUISINE a on c.NumCuisine = a.NumCuisine
Thus, we request, by writing an SQL expression, a predicate associated with it characterizing the relationship of the application (aka association) whose rows we want.
FKs (foreign keys) are not relationships.
FK restrictions are called some people's relationships, but they are not. These are the facts.
A FK table is a collection of columns. βFKβ is also used to denote the associated restriction that we have when we have FK. Which, like any restriction, is a true statement in every state of the database. (Equivalent, each application situation.) The FK constraint says that values ββfor certain columns in a specific table are also values ββfor certain columns in some other table, where they form CK (candidate key). (Equivalently, he says that if some values ββ/ entities satisfy certain application relationships, then some of them plus some other values ββ/ entities satisfy some other application relationship, where the values ββ/ entities form CK.) PK (primary keys) are just some CK, which you decide to call PK.)
The FK constraint has a certain relation to related applications, but this does not mean that the relation is used for the FK (restriction) relation. ("FK" is also used to indicate the substring value for FK columns or the value in a row for a single-column FK column.)
You need to know what each table means.
Predicates must be supplied by the designer along with the schema. You need to find out what the tables mean. Then express your query predicate in terms of them. Then convert to SQL.
Sometimes we guess predicates more or less successfully through common sense and naming. FCs and other restrictions can help guessing.
Common sense, names, PKs (underlined?) And FKs ("#"?) Offer you table values:
-- chef with id NUMCUISINIER has name NOMCUIS and start date DATEEMB and works in kitchen with id NUMCUISINE CUISINIER(NumCuisinier, NomCuis, NateEmb, NumCuisine) -- kitchen with id NUMCUISINE has phone number TELCUISINE and chef with id NUMCUISINIER as head chef ATELIER_CUISINE(NumCuisine, TelCuisine, NumCuisinier)
FK not needed for request
In the SQL query above, the rows that predicates enter in the true statement always return rows. It does not matter how many rows exist for the NumCuisiner or NumCuisine (i.e., Are they PK) or should the value appear in another table (i.e., are they FK). Or any other restrictions.
We need to know the predicates for the query. When we know them, we do not need to know any restrictions. We do not need to know FK.
FKs, CKs, PK, alternative keys and UNIQUE columns (superclasses) are not relevant to the request, except that if you know that something is a superkey because of one, then you can write queries related to the extraction of the value from a single row result. But you could express the same result without any extra exits.