You now consider the practical application of de-normalization. Pull the SQL command files from
our standard repo: code/04modeling
directory. For this lab, plan to complete the
analysis portion for the lab and the programming portion for the homework.
Study the schema and sample data specified for the AltPerson
relation (lab04_1.sql
),
noting that no primary or foreign keys are specified at this point and that the data reflect
the pathologies of the schema. The table is intended to represent information on people in
the Centrepointe church domain, their mentors and their team memberships, e.g., Shamkant in
the chair of the elders and the mentor of Ramez.
Explain, informally, why the relation is not well-designed and then prove your point formally.
Specify a properly normalized schema for this database.
[Homework] Implement an appropriately normalized version of the
AltPerson
relation by editing the existing command file, adding your own
create-table commands below the ones already in the file and using different table names
to avoid naming conflicts. Your commands should do the following.
[Optional challenge] Write a query the reproduces the old data table from your new tables.
Specify your solutions to the conceptual questions in clearly-labeled comments in the original command file, then add your programmed solution for the homework.
You can insert data from existing tables into new tables using the following SQL INSERT command form:
INSERT INTO newTable SELECT existingFields FROM existingTable;
Now, consider another de-normalization problem.
Study the schema and sample data for persons, teams and visits (lab04_2.sql
).
The tables represent information on people, their (potentially many) team memberships and
their (potentially many) church visits, e.g., Shamkant is an elder and he visited on Feb 22.
Demonstrate, formally, whether the relations implemented by the tables PersonTeam
and PersonVisit
are in BCNF and/or 4NF (or not).
Consider the output of the data queried by the combined “view” query at the end of the command file. Demonstrate, formally, whether this view, when considered as a (single) relation, is in BCNF and/or 4NF (or not).
The view has the same number of records as the original tables. Does this mean that the original schema and the derived “view” schema are equally appropriate? If so, explain why; if not, explain why one of the schemata is better. Does your choice depend on context?
[Homework] Create a new table to store the data queried by the combined “view” query at the end of the command file and load it with the queried data. Note that you can load the data either using hard-coded INSERT commands (for some credit) or by inserting data selected from the original tables (for full credit).
Specify your solutions to the conceptual questions in clearly-labeled comments in the original command file, then add your programmed solution for the homework.
See the text for a discussion of inserting selected data rather than hard-coded data (i.e.,
INSERT INTO … SELECT … ;
).
We will grade your work according to the following criteria:
Exercises 4.1.c and 4.2.d are graded with the homework.