Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HW1 - Relational Algebra The database you will use for this assignment contains information related to Major League Baseball (MLB) about players, teams, and games.

HW1 - Relational Algebra

The database you will use for this assignment contains information related to Major League Baseball (MLB) about players, teams, and games. The relations are:

Players(playerID, playerName, team, position, birthYear)

? playerID is a player identifier used in MLB, and all players throughout the history of baseball have a unique ID

? playerName is players name

? team is the name of the MLB team the player is currently playing on (or the last team the player played for if they are not currently playing)

? position is the position of the player

? birthYear is the year that player was born

Teams(teamID, teamName, home, leagueName)

? teamID is a unique ID internal to MLB.

? teamName is the name of the team

? home is the home city of the team

? leagueName is the league the team is in, i.e. either National or American, which stands for National League and American League, respectively

Games(gameID, homeTeamID, guestTeamID, date)

? gameID is a unique ID used internally in MLB

? homeTeamID is the ID of the hometeam

? guestTeamID is the ID of the visiting team

? date is the date of the game.

A sample instance of this database is given at the end of this homework handout. Since it is just one instance of the database designed to give you some intuition, you should not customize your answer to work only with this instance.

1. (5 points each) Consider the schema given above:

(a) Give a primary key for each relation. Are there any relations for which there is an alternate candidate key which you have not chosen as the primary key? If yes, mention the relations, candidate keys and the reason (if any) for your choice of the primary key.

(b) State all referential integrity constraints (inclusion dependencies) that should hold on these relations.

(c) Note that there is no way to represent the fact that a player may have played on several different teams (for example, Javy Lopez played for the Braves, Orioles and RedSox before retiring), or that they are currently retired. How would you modify the schema to take this into account? (Hint: try to do it in a way that information is not repeated unnecessarily.)

For the next parts, if a query is long, feel free to break it up into a series of queries with intermediate answers stored in temporary relations (e.g. let temp =.....). You may also use just the first letter of each relation name since they are unique (e.g. P" for Players"). Also, for the ease of typing, you can use words for operations (e.g., proj for projection) Note: Your queries must not be state-dependent", that is, they should work without modification even if another instance of the database is given.

2. (8 points each) Write the following queries in relational algebra, using the schema provided above.

(a) Print the names of all players who were born in 1970 and played for the Braves.

(b) Print the names of teams that do not have a pitcher.

(c) Print names of all players who have played in the National League.

(d) Print all gameIDs with Phillies as the home team.

(e) Print all teamIDs where the team played against the Phillies but not against the Braves.

3. (15 points each) Write the following queries in relational algebra, using the schema provided above.

(a) Define a relation Members(playerID1, playerID2, team) where playerID1 and playerID2 are (or have been) on the same team. Avoid listing self-references or duplicates, e.g. do not allow (1,1,Braves) or both (2,5,Phillies) and (5,2,Phillies).

(b) Define a relation WorldSeries(teamID1, league1, teamID2, league2, date) where teamID1 and teamID2 played against each other in a World Series game. Although there is no direct information about the World Series in the relations, we can infer that when two teams from different leagues play each other, it is a World Series game. So, in this relation, league1 and league2 should be different leagues.

(c) Define a relation AllLeagues(city) for which each city has a team in all leagues. For example, there are currently two leagues (National and American). Although not shown in this instance, New York is home to the Mets in the National league as well as the Yankees in the American league (Chicago also has one in each league, for those of you who are baseball fans). Remember that your query must work over all instances of this schema, even if there are more than two leagues in the instance

image text in transcribed

image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago