You are on page 1of 6

BINDURA UNIVERSITY OF SCIENCE EDUCATION

NAME SIMBAINASHE MUSHAMBI


REG NUMBER B193385B

PROGRAMME INFORMATION `
TECHNOLOGY

COURSE NAME ADVANCED DATABASE


COURSE CODE CS413
ASSIGNMENT 2
PART 4.2
YEAR 2023
a) Transform the following ER model to a database schema, identifying the primary keys and
foreign keys. [12]

We can transform the given ER model into a database schema. The following is the schema
with identified primary keys (PK) and foreign keys (FK):
1) Table: Appointments Columns: id (PK), description ,date ,time, patient_id (FK references
patient.id)
2)Table: Patient Columns: id (PK) ,name, address, sex ,age, dob
3) Table: Dues Columns: id (PK), amount, date ,patient_id (FK references patient.id)
4)Table: Test Columns: id (PK), description
5)Table: Clinic Columns: name
6)Table: Doctor Columns: id (PK), name, specialization ,visitinghrs, patient_id (FK
references patient.id)
Relationship: Patient visits Appointment Foreign Key: patient_id (refers to Patient.id)
Relationship: Patient visits Doctor Foreign Key: patient_id (refers to Patient.id)
Relationship: Patient has Dues Foreign Key: patient_id (refers to Patient.id)
Relationship: Patient has Test Junction Table: Patient_Test Columns: patient_id (FK
references patient.id) test_id (FK references test.id)
Relationship: Patient has Test at Clinic
Junction Table:Patient_Test_Clinic
Columns: patient_id (FK references patient.id) ,test_id (FK references test.id), clinic_id (FK
references clinic.id)
In this transformed database schema, the primary keys (PK) are identified with the suffix
"(PK)" and the foreign keys (FK) with the suffix "(FK)" in the table definitions. The
relationships are represented either through direct foreign key references or through junction
tables for many-to-many relationships.

a) Given R (A, B, C, D, E) with the set of FDs, F {AB CD, A E, C D}. Is the
decomposition of R into R1 (A,B,C), R2 (B,C,D) and R3(C,D,E) lossless? Prove.

c) Suppose you are given a relation R = (A,B,C,D,E) with the following functional
dependencies: {CE D,D B,C A}.

i) Identify the best normal form that R satisfies. [2]


First, we see that CE → D, which means that D is functionally dependent on CE.
This suggests that we should create a new relation with attributes CE and D.
Next, we see that D → B, which means that B is functionally dependent on D.
This suggests that we should create a new relation with attributes D and B.
Finally, we see that C → A, which means that A is functionally dependent on C.
However, since A is not part of any other functional dependency in R, it does not suggest the
need for a new relation.
After this decomposition process, we end up with three relations: R1 = (C, A) R2 = (CE,D)
R3 = (D,B)
Each of these relations has a single candidate key and no transitive dependencies, which
means they are all in 3NF. Therefore, R satisfies 3NF.

ii)If the relation is not in BCNF, decompose it until it becomes BCNF. At each step, identify
a new relation, decompose and re-compute the keys and the normal forms they satisfy. [4]

Since relation R is already in BCNF, there is no need for further decomposition.


However, if the relation were not in BCNF, we would proceed with decomposition until it
satisfies BCNF.
Start with relation R = (A, B, C, D, E) and the given functional dependencies: {CE -> D, D -
> B, C -> A}.
Determine the candidate keys of R: From the given dependencies, we can infer that the
candidate key is CE. (CE uniquely determines all attributes in R.)
Check if R satisfies BCNF. Since the left side of each dependency is a superkey, R satisfies
BCNF.
If R were not in BCNF, we would decompose it by splitting the relation based on the
functional dependencies and create new relations as needed.
Since R is already in BCNF, no further decomposition is required

c) Prove the Armstrong’s union rule [4]


Reflexive Rule (IR1)

If X ⊇ Y then X  →    Y  

Augmentation Rule (IR2)

If X    →  Y then XZ   →   YZ   

Transitive Rule (IR3)


If X   →   Y and Y  →  Z then X  →   Z    

Union Rule (IR4)

Union rule says, if X determines Y and X determines Z, then X must also determine Y and Z.

If X    →  Y and X   →  Z then X  →    YZ     

Proof:

1. X → Y (given)
2. X → Z (given)
3. X → XY (using IR2 on 1 by augmentation with X. Where XX = X)
4. XY → YZ (using IR2 on 2 by augmentation with Y)
5. X → YZ (using IR3 on 3 and 4)

i) Define the two integrity rules. [4]


1. Entity Integrity Rule: This rule states that each row or record in a table must have a unique
identifier, known as a primary key. This ensures that there are no duplicate records in the
table.
2. Referential Integrity Rule: This rule ensures that relationships between tables are
maintained by requiring that any foreign key values in one table must match a primary key
value in another table.

ii)Explain with examples how these rules are important to enforce consistent database states.
[6]
The entity integrity rule is important to enforce consistent database states because it ensures
that each record is unique and can be easily identified. For example, if a customer database
did not have a primary key, it would be difficult to distinguish between two customers with
the same name and address. Primary keys ensure that any prime attribute must not be NULL.

The referential integrity rule is important to enforce consistent database states because it
ensures that data is accurate and reliable. For example, if an order database did not have
referential integrity, it would be possible for an order to be associated with a non-existent
customer or product. Referential integrity ensures that the values in the foreign key must
belongs to it parent key or it may be entirely NULL.
e) Given the dependency diagram shown in the following figure describe each of the
indicated dependencies. [6]

The FDS for the given relation are:


1. C1→ C2
2. C1, C3 → C2, C4, C5
3. C4 → C5
The Primary key of the given relation is (C1, C3), so C1 →C2 is a partial FD and there is a
transitive FD also :
C1, C3 →C4 →C5 in the relation.

You might also like