



























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




























































Multiple Tables and Relationships
15 The Hunger Games 2012 142 PG 41 Silver Linings Playbook 2012 122 MA 135 The Hangover 2009 100 MA 156 X-Men Days of Future Past 2014 101 PG
RATINGCODE RATINGNAME DESCRIPTION G General Suitable for all ages PG Parental Guidance Recommended for mature audiences 15 years and over M Mature (15+) Persons under 15 years must be accompanied by a mature adult MA Mature Accompanied Parental guidance recommended for persons under 15 years (15+) R Restricted (18+) Restricted to mature adults 18 years and over
This is a Many to One relationship. Many FKs refer to one PK. Foreign Key movieNo title relyear runtime ratingcode 15 The Hunger Games 2012 142 PG 41 Silver Linings Playbook 2012 122 MA 135 The Hangover 2009 100 MA 156 X-Men Days of Future Past 2014 101 PG Primary Key RatingName Description ratingcode G General Suitable for all ages PG Parental Guidance Recommended for mature audiences 15 years and over M Mature (15+) Persons under 15 years must be accompanied by a mature adult MA Mature Accompanied (15+) Parental guidance recommended for persons under 15 years R Restricted (18+) Restricted to mature adults 18 years and over
Now design a new Query using both the Movie and Rating tables. As you add the tables to the query, the relationship is shown. This query has data from both tables. The query matches every FK value in the Movie table with a PK value in the Rating table.
Imagine that you did not create the relationship between the Movie and Rating tables. They are simply two unrelated tables. When you create a query, the RDBMS does not know what these tables have in common There is no connection between the rating codes in the two tables (at least that's what the RDBMS thinks).
If you run a query that uses data from both unrelated tables, then a ' cartesian product ' is created. Every row in movie table matches every row in the ratings table. 318 movies * 5 ratings = 1590 rows! Utterly useless. Can be very slow to create. AVOID
actorNo firstname surname gender 72129 Jennifer Lawrence F 51329 Bradley Cooper M 1245 Scarlett Johansson F 6968 Hugh Jackman M
movieNo title relyear runtime ratingcode 70160 The Hunger Games 2012 142 PG 82693 Silver Linings Playbook 2012 122 MA 18785 The Hangover 2009 100 MA 127585 X-Men Days of Future Past 2014 101 PG actorNo firstname surname gender 72129 Jennifer Lawrence F 51329 Bradley Cooper M 1245 Scarlett Johansson F 6968 Hugh Jackman M