5 | due Monday 9 Dec |
For Assignment 5: Create a Database with a Many-to-many (M:M) Relationship
For your database create tables with a M:M relationship between two independent
entity classes. Consider entity classes from the
M:M Database Choices.
Each independent entity should have a single theme. Attributes or columns chosen
for each class should be atomic and essential. Use natural language names for
the tables and columns, minimize the use of abbreviations for identifiers and
and data values (verify spelling). The database schema should include attributes
for each of the major data types: int, date or year, fixed or variable-length
character, and decimal with fraction. The tables for the independent entities
should have three or more non-key attributes. The table defined for the
associative entity should have one or more non-key attributes.
Tables created should have data types and lengths consistent with the authentic
data. Use case consistently for the data values. Define primary and foreign keys
to enforce entity and referential integrity.
Table data should include all known instances or a meaningful subset of
authentic data. Also, the data stored should illustrate M:M, 1:M, M:1,
1:1, 1:0 and 0:1 participation constraints.
Complete the following steps to show your login and environment, table design
and to confirm the data depict the relationships specified above:
0) Show tables and issue "show create table" statements for the two independent
classes and the associative entity.
1) Query each of the tables to project all columns. Include an order by clause
on the querys to highlight those columns designated as primary keys;
2) Prepare querys with nested querys to document the M:M relationship:
a. Reference one independent entity in a superQuery that matches multiple
rows in the associative entity, which will then match rows in the other
independent entity (e.g. a superQuery on Student with nested query of
the associative entity Enrollment with a nested query of Course to show
some student is enrolled in multiple courses).
b. Then reference the other independent entity in a superQuery to produce
multiple rows illustrating the other end of a m:m relationship (e.g.
for one of the courses listed in result 2a, list students related
to (enrolled in) that course.
3) Define a join view based on a query joining the three tables. This
view should include columns corresponding to the primary key and one non-key
column from each of the independent entities, plus the keys and one non-key
column from the associative entity. Query this view with columns projected as
indicated above and rows ordered by the key columns from the two independent
entities.
4) Prepare correlated subquerys with the NOT EXISTS operator to show that there
are independent entity instances not related to the other independent entity
(1:0, and 0:1). For example a Student that is not enrolled in any Course; and
a Course with no Student enrollees.
Note:
For this 20-point assignment prepare a text file(.txt) containing only valid
query commands and results; and attach this file to an email sent to tom.brown
at the domain tamuc.edu on or before Monday 9 December. The email subject line
is to list our course code, your name, and the assignment number.
|