Docsity

Database Normalization: Understanding 2NF and 3NF Violations and Solutions, Slides of Database Management Systems (DBMS)

Toggle sidebar
bg1
Q # 1 (01)
1. Characterize the difference between the following pairs of
terms
a. Entity and entity class
b. Relationship and relationship type
c. Attribute value and attribute
d. Strong entity class and weak entity class
2. Create an ER model for the following enterprise:
Each building in an organization has a different building
name and address. The meeting rooms in each building
have their own room numbers and seating capacities.
Rooms may be reserved for meetings, and each meeting
must start on the hour. The hour and length of use are
recorded. Each reservation is made by a group in the
company. Each group has a group number and a contact
phone.
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39

Partial preview of the text

Download Database Normalization: Understanding 2NF and 3NF Violations and Solutions and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

Q # 1 (01)

1. Characterize the difference betw een the follow ing pairs of

term s

a. Entity and entity class

b. R elationship and relationship type

c. Attribute value and attribute

d. Strong entity class and w eak entity class

2. Create an ER m odel for the follow ing enterprise:

Each building in an organization has a different building

nam e and address. The m eeting room s in each building

have their ow n room num bers and seating capacities.

R oom s m ay be reserved for m eetings, and each m eeting

m ust start on the hour. The hour and length of use are

recorded. Each reservation is m ade by a group in the

com pany. Each group has a group num ber and a contact

phone.

Q# 1 (01): Solutions

 a. Entity and entity class

 An entity is an object and an entity class is a

collection of objects.

 b. R elationship and relationship type

 A relationship is a specific instance of two related

entities. A relationship type represents the possibility

that two entities are related.

 c. Attribute value and attribute

 An attribute is a characteristic shared by entities of a

class. An attribute value is the particular value of the

attribute for a specific entity.

 d. Strong entity class and w eak entity class

 A strong entity class is one with a key and a weak

entity class has no key of its own.

Q #1 (02)

  1. Consider the following E-R diagram

and attributes

Buyer: id, name, address

Property: id, askingPrice, salePrice,

address

StaffMember: id, lastName, firstName,

phone

Branch: id, name, address, phone

a. Write sentences to describe the roles

of staff members in the diagram.

b. Write sentences to describe the roles

of property in the diagram.

  1. Explain the following constraints.

a. Domain constraint

b. Key constraint

c. Cardinality constraint

d. Participation constraint

Branch
M
StaffMember
M
Works
At
Buyer Proprety
Sells
Buys
Manages
M
M

Q#1 (02) Solution

a. Write sentences to describe the roles of staff members in the diagram.

 A staff member may sell many properties.

 A staff member may work at a branch.

 A staff member may mange a branch

b. Write sentences to describe the roles of property in the diagram.

 A property may be bought by one buyer

 A property may be sold by many staff members

a. Domain constraint : restrictions on the allowable values of attributes - the type

and the range of values possible for each attribute

b. Key constraint : unique value in an entity class-most entity classes have one or

more attributes that form a key of the class

c. Cardinality constraint : the number of relationships that may exist at a time –

(to-one and to-many)

d. Participation constraint : whether at least one relationship must exist for each

entity of a class.

Q#2 -01 : solution

 Building (name, address)

 Room (number, capacity, type, buildingName)

 Meeting (name, date, hour, length, roomNo, byGroup)

 Group (number, contact, phone)

Q # 2 (02)

  1. Create a relational database schema for

the following EER model.

d

Vehicle

weight

vehicleId

capacity

number Wheels

Car

numberDoors amenities

Truck

number Axles

weight Capacity

Motorcycle

engineType usage

M Has Owner

M

ssn
firstName
lastName

Q # 2 (02): solution

1. One of the possible solutions

Vehicle (vehicleId, weight, capacity, numberWheels)

Car (vehicleId, numberDoors, amenities)

Truck (vehicleId, weightCapacity, numberAxles)

Motorcycle (vehicleId, engineType, usage)

Owner (ssn, firstName, lastName)

Has (ssn, vehicleId)

Q # 2 (02): solution

a. Which sets of attributes are the keys of R?

{A, B} and {A, C}

b. Identify and eliminate any 2NF violations.

C → {E, F} is a 2NF violation

The revised schema is

R9: (A, B, C, D, G, H), {A, C} is also a key

R10: (C, E, F)

c. Identify and eliminate any 3NF violations.

G → H is a 3NF violation

The revised schema is R10,

R11: (A, B, C, D, G), {A, C} is also a key

R12: (G, H)

Q # 3 (01): Solutions

Create table Department (

Dnumber int primary key, Dname varchar(20), MgrSSN int references Employee );

Create table Employee (

SSN int primary key, Fname varchar(20), Lname varchar(20), Sex char(1), Salary int,

SuperSSN int references Employee, Dno int references Department );

Select Fname, Lname from Employee, Department where Dname=‘Research’ and

Dnumber = Dno;

Insert into Department (Dnumber, Dname) values (6, “Sales”);

Q # 3 (02)

  1. Write a SQL select statement to find the names of all employees whose salaries are greater than 30000.
  2. Write a SQL select statement to find the names of departments for which female employees

work.

  1. Write a SQL statement to delete all the employees who work at Dno 4.

Department DNumber DName MgrSSN

5 Research 333445555

4 Administrator 987654321

1 Headquarter 888665555

Employee SSN FName LName Sex Salar y

SuperSSN Dno

123456789 John Smith M 30000 33344555 5

333445555 Franklin Wong M 40000 88866444 4

999887777 Alicia Zelaya F 25000 98765432 1

987654321 Jennifer Wallace F 43000 88866555 5

666884444 Ramesh Narayn M 38000 33344555 5

453453453 Joyce English F 25000 33344555 5 Docsity.com

Manipulating Information with

the Relational Algebra [Ch. 6.1]

 Relation is a set of tuples and that each

tuple in a relation has the same

number and types of attributes.

Relational algebra includes :

 Selection Operators

 Projection Operators

 Set Operators

 Join and product Operations

Selection Operators (σ)

 Reduce the number of tuples in a set by selecting those that

satisfy some criteria.

 Example : σ lastName = ‘Doe’ (Customer) [ Select from Customer where lastName = ‘Doe’ ]

Customer

Account Id

Last Name

First Name

Street City State Zip Code

Balance

101 Block Jane 345 Randolph Circle Apopka FL 30458- $0.
102 Hamilton Cherry 3230 Dade St. Dade City FL 30555- $3.
103 Harrison Katherine 103 Landis Hall Bratt FL 30457- $31.
104 Breaux Carroll 76 Main St. Apopka FL 30458- $35.
106 Morehouse Anita 9501 Lafayette St. Houma LA 44099- $0.
111 Doe Jane 123 Main St. Apopka FL 30458- $0.
201 Greaves Joseph 14325 N. Bankside St. Godfrey IL 43580- $0.
444 Doe Jane Cawthon Dorm, room 142 Tallahassee FL 32306- $10.

Set Operators (∪ ∩ -)

 Manipulate two similar sets of tuples by combining or

comparing.

 Example : Rental ∪ PreviousRental

Rental PreviousRental

accountId videoID dateRented dateDue cost
accountId videoId dateRented dateReturned cost

Set Operators (∪ ∩ -) ...con’t

• The union of two relations is a relation that contains the set

of each tuple that is in at least one of the input relations.

Partial result of the Rental ∪ PreviousRental

accountId videoId dateRented dateDue cost

101 90987 1/1/99 1/8/99 $2.

101 99787 1/1/99 1/4/99 $3.

103 101 1/3/99 1/4/99 $1.

103 123 12/1/98 12/31/98 $10.

111 101 12/4/98 12/6/98 $2.

201 77564 1/14/99 1/24/99 $3.