Вы находитесь на странице: 1из 3

ITE

407 ADVANCED DATABASE MANAGEMENT SYSTEMS - Laboratory Exercise 0.1

Theory

Databases have the function of enabling data integrity in various ways. One of the ways that this is done
is by ensuring that related tables have constraints such as primary keys that are unique, and not null,
foreign keys that will not get orphaned in the event that a parent row is removed from the main table,
or if a change is made to a primary key in the parent table. An orphaned relation, or table, is one that
does not have any relationship with a parent table record. This usually introduces inconsistencies in a
database if it is allowed to perpetuate.

Objective

The objective of this exercise is to demonstrate referential integrity as a way of encapsulating overall
data integrity in table structures.

Tools/Applications

MySQL is preferred to demonstrate the DDL commands. MS Access maybe used if MySQL is not
accessible.

Lab Activity:

1. Open MySQL or Microsoft Access and create a database called Class_Ex1.




2. Create two tables with the following characteristics:

TABLE 1: STUDENT (Student_ID CHAR(6),First_name CHAR(10), Last_name CHAR(10));
TABLE 2: COURSE (Course_ID CHAR(6), Course_Name CHAR(12), Location_ID NUMBER(3));

TABLE 1 will have Student_ID as the primary key, and TABLE 2 will have Course_ID as the
primary key.

These two tables define your Master file status. The rate of change of this file will not be high.


3. Create a new table with the following characteristics:

TABLE 3: SEMESTER_COURSE (Student_ID CHAR(6), Course_ID CHAR(6), Semester NUMBER(2));

This table will have no primary key. However, the Student_ID is a foreign key into the STUDENT
table (TABLE 1), and the Course_ID is a foreign key into the Course table (TABLE 2).

This table defines a transaction file status. Semester activity can be renewed or initialized with
each semester.

4. Establish one-to-many relationships between TABLE 1 and TABLE 3 with cascading properties. This
ensures that DML activities such as deleting, insertions, and modifications are tied and verified
between any two tables.

5. Establish one-to-many relationships between TABLE 2 and TABLE 3, repeating the cascading
properties that were done in step 4 above.

6. Enter the following data in the STUDENT table:

Student_ID First_Name Last_Name
01-001 John Chambers
01-002 William Gates
01-003 Mark Zukerberg
01-004 Charles Branson

7. Next, enter the following data in the COURSE table:

Course_ID Course_Name Location
CMP101 Intro to Logic 03
CMP102 Parallel Programming 05
CMP103 Business Computing 07
CMP104 Social network design 09

8. Now populate the SEMESTER_COURSE table:

Student_ID Course_ID Semester
01-001 CMP101 02
01-002 CMP102 02
01-003 CMP101 02
01-004 CMP104 02

Duplicate entries have not been taken care of in terms of course IDs. This is not the concern of this
class exercise.
9. Student 01-001 will need to take CMP103 and CMP104. He also needs to take a course called
CMP105. Enter these data. Ensure that CMP105 is inserted (from the transaction table position) with
the course name Accounting for IT.

10. Course CMP102 is no longer offered and is being removed from COURSE table. Remove this course
from the main table first. Notice what happens with respect to referential integrity.

11. Each of the students must take all four courses for the semester. Can you ensure this from the main
course file?

Reflection

1. How would you design your relationship to ensure that an update cascades? Is it possible to
cascade an update with the present setup?

2. What would happen if the relationship between COURSE and SEMESTER was released (or
removed), and some data inserted into SEMESTER (CMP106, CMP107) and then the
relationship re-established?

3. Why would it be useful to enforce a deletion cascade?

Tuesday, February 7, 2017

Вам также может понравиться