What Kind of Relationship is Between These Tables?

前端 未结 4 1521
不思量自难忘°
不思量自难忘° 2020-12-02 01:44

I have two tables that have foreign keys to each other\'s primary key. This DB is in French. I will translate the two tables that I want to you to understand.

4条回答
  •  被撕碎了的回忆
    2020-12-02 01:51

    IMHO, this "key exchange" is plainly wrong; from the sample data we may conjecture (but not for sure!) that the relationship between [ATELIER CUISINE] and [CUISINER] is one-to-many (CUISINIER table), in which case the [ATELIER CUSINE] should NOT have the NumCuisinier column, or otherwise NumCuisine is not a Primary Key (which, according to the data model, is)! So the data model is probably wrong.

    My best bet for your query would be

    SELECT B.*, A.TelCuisine
    FROM [ATELIER CUISINE] A INNER JOIN CUISINIER B ON A.NumCuisine = B.NumCuisine
    

    Unless of course NumCuisinier in [ATELIER CUISINIER] table is NOT a FK, as @marcothesane suggests and it has a completely different meaning, in which case it should be contained in the result set (but with a different alias):

    SELECT B.*, A.TelCuisine, A.NumCuisinier as [HeadChef]
    FROM [ATELIER CUISINE] A INNER JOIN CUISINIER B ON A.NumCuisine = B.NumCuisine
    

提交回复
热议问题