Assignment 4. Database Design

Objectives

This assignment has two parts.

Download A4.zip. Answer the questions in A4.ipynb.

Part 1. Entity-Relationship Model (10 points)

You will design a database for SFU. This database will include information about departments, students, courses (and their offerings):

Please note that the following two sentences are not constraints (you don't need to enforce them in your ER-diagram). They just tell you what data might be like. 

  1. Assume that for a course to be offered during a term, it has at least one student enrolled

  2. Assume that a student can take courses “owned” by departments with which the student is not affiliated

Task 1: E/R Diagram (5 points)

Render the SFU database in the version of the E/R model that we studied in class, with exactly the constraints and requirements specified above.

Drawing

Task 2: From E/R Diagram to Relational Schemas (5 points).

Please follow the above E/R Diagram and write SQL queries to create required tables in sfu.db

Part 2. Normalization (10 points)

Task 3. Decompose a relational schema into BCNF

Consider a relational schema and a set of functional dependencies:

Decompose $R(A,B,C,D,E)$ into BCNF. Show all of your work and explain, at each step, which dependency violations you are correcting. You have to write down a description of your decomposition steps. (2 points)

Task 4. Find a set of FDs that is consistent with a closed attribute set

A set of attributes $X$ is called closed (with respect to a given set of functional dependencies) if $X^+=X$. Consider a relation with schema $R(A,B,C,D)$ and an unknown set of functional dependencies. For each closed attribute set below, give a set of functional dependencies that is consistent with it.

a. All sets of attributes are closed (1 point)

b. The only closed sets are $\{\}$ and $\{A,B,C,D\}$ (1 point)

c. The only closed sets are $\{\}$, $\{A,B\}$, and $\{A,B,C,D\}$ (1 point)

Task 5. Normalize a database

Suppose Mike is the owner of a small store. He uses the following database (mike.db) to store monthly sales of his store.

However, Mike finds that the database is difficult to update (i.e., when inserting new data into the database). Your job is to help Mike to normalize his database. You should do the following steps(a-d):

a. Find all nontrivial functional dependencies in the database. This is a reverse engineering task, so expect to proceed in a trial and error fashion. Search first for the simple dependencies, say $name \rightarrow discount$ then try the more complex ones, like $name, discount \rightarrow month$, as needed. To check each functional dependency you have to write a SQL query.

Your challenge is to write this SQL query for every candidate functional dependency that you check, such that:

Write down all FDs that you found. (1 point)

For each FD above, write down the SQL query that discovered it (remember short queries are preferred) (1 point)

b. Decompose the Sales table into BCNF. Like Task 1, show a description of your decomposition steps. (1 point)

c. Write down SQL queries to create the BCNF tables in the mike.db. Create keys and foreign keys where appropriate. (1 point)

d. Populate the BCNF tables using the data from the sales table. (1 point)

Hint: see SQL INSERT INTO SELECT Statement

Submission

Download A4.zip. Answer the questions in A4.ipynb. Put A4.ipynb, ER-diagram.png, sfu.db, and the mike.db (with populated BCNF tables) into A4-submission.zip.

Submit A4-submission.zip to the CourSys activity Assignment 4.