You are on page 1of 24

Ex 1.

Employees Database
Employee Table

employee_id last_name first_name branch


1002 Smith Jo Ferrymead
1006 Rangi Ann-Marie Sydenham
1008 Henry Geoff Westfield Manukau
1010 Wang Li The Grove

Branch Table

branch branch_city Identify the primary keys and foreign keys


share phone numbers - each phone numbe
Ferrymead Christchurch
Sydenham Christchurch
Westfield Manukau Manukau
The Grove Nelson
Phone Table

number phone_type
4335667 home
021654321 mobile
02096543 mobile
8334567 home

y keys and foreign keys in the tables - add any that are missing. For this simple example we assume people cannot
ers - each phone number is unique and belongs to one person.
example we assume people cannot
Ex 1. Employees Database
Employee Table

employee_id (PKey) last_name first_name branch (FKey)


1002 Smith Jo Ferrymead
1006 Rangi Ann-Marie Sydenham
1008 Henry Geoff Westfield Manukau
1010 Wang Li The Grove

Branch Table

branch (PKey) branch_city Note the foreign keys (FKey). We had to ad


Ferrymead Christchurch
Sydenham Christchurch
Westfield Manukau Manukau
The Grove Nelson
Phone Table

number (PKey) phone_type


4335667 home
021654321 mobile
02096543 mobile
8334567 home

eys (FKey). We had to add employee_id to the Phone table to link the phone numbers with the employees.
employee_id (FKey)
1002
1002
1008
1010

mbers with the employees.


Ex 2. Dental Appointments Database
Appointment Table

appointment_number date time


6000 8/17/2022 10:00
6001 8/17/2022 13:00
6002 8/17/2022 10:00
6003 8/17/2022 12:00

Appointment Reason Table

appointment_number reason
6000 Checkup
6000 Broken Tooth
6001 Checkup
6002 Crown Fitting
6003 Cleaning
6003 Checkup

Reason Table
reason
Broken Tooth
Checkup
Cleaning
Crown Fitting
staff_number patient_number surgery_room_number
S1000 P100 1
S1000 P105 2
S1010 P208 2
S1010 P302 1

Staff Table

staff_number first_name last_name


S1000 Jo Smith
S1010 Wu Zao

Patient Table
patient_number first_name last_name
P100 Ann-Marie Rangi
P105 Priya Kaur
P208 Bob Brown
P302 Kerryn Painter
Ex 2. Dental Appointments Database
Appointment Table

appointment_number (PKey) date time


6000 8/17/2022 10:00
6001 8/17/2022 13:00
6002 8/17/2022 10:00
6003 8/17/2022 12:00

Appointment Reason Table

appointment_number (PKey) (FKey) reason (PKey) (FKey)


6000 Checkup
6000 Broken Tooth
6001 Checkup
6002 Crown Fitting
6003 Cleaning
6003 Checkup

Reason Table
reason (PKey)
Broken Tooth
Checkup
Cleaning NOTE: Although there is a surrogate
Crown Fitting
staff_number (FKey) patient_number (FKey) surgery_room_number
S1000 P100 1
S1000 P105 2
S1010 P208 2
S1010 P302 1

Staff Table

staff_number (PKey) first_name last_name


S1000 Jo Smith
S1010 Wu Zao

Patient Table
patient_number (PKey) first_name last_name
P100 Ann-Marie Rangi
P105 Priya Kaur
P208 Bob Brown
P302 Kerryn Painter

gh there is a surrogate PKey in the Appointment table, is there a business/natural key?


Ex 3. Temporary Hotel Staff Database
Contract Table
contract_num hotel_code start_date
1001 H123 8/1/2022
1002 H354 8/2/2022

Hotel Table
hotel_code hotel_location
H123 Sydenham
H354 Sumner

Employee Table
ird_num first_name last_name
123456 Anna Kramnik
456789 Jim Green
98765 Taihana Robinson

Employee Contract Table


ird_num contract_num hours_per_week
123456 1001 10
456789 1002 15
98765 1002 20
Ex 3. Temporary Hotel Staff Database
Contract Table
contract_num (PKey) hotel_code (FKey)
1001 H123
1002 H354

Hotel Table
hotel_code (PKey) hotel_location
H123 Sydenham
H354 Sumner

Employee Table
ird_num (PKey) first_name
123456 Anna
456789 Jim
98765 Taihana

Employee Contract Table


ird_num (PKey) (FKey) contract_num (PKey) (FKey)
123456 1001
456789 1002
98765 1002
start_date
8/1/2022
8/2/2022

last_name
Kramnik
Green
Robinson

hours_per_week
10
15
20
Ex 4. Car Sales Database
Car Table
car_registration_number car_make
ABC123 Toyota
DEF234 Subaru
GHI345 Volvo

Salesperson Table
salesperson_id first_name
1002 Hemi
1050 Janet

Car Sales Table


car_registration_number date_sold
ABC123 8/2/2022
DEF234 8/3/2022
GHI345 8/3/2022
ABC123 12/10/2022
car_model
Corolla
Impreza
XC-90

last_name commission_percentage
Brown 5
Jones 6

salesperson_id discount_amount sale_price


1002 0 7500
1050 1000 4000
1002 1200 12000
1050 500 6500
Ex 4. Car Sales Database
Car Table
car_registration_number (PKey) car_make
ABC123 Toyota
DEF234 Subaru
GHI345 Volvo

Salesperson Table
salesperson_id (PKey) first_name
1002 Hemi
1050 Janet

Car Sales Table


car_registration_number (PKey) (FKey) date_sold (PKey)
ABC123 8/2/2022
DEF234 8/3/2022
GHI345 8/3/2022
ABC123 12/10/2022
car_model
Corolla
Impreza
XC-90

last_name commission_percentage
Brown 5
Jones 6

salesperson_id (FKey) discount_amount sale_price


1002 0 7500
1050 1000 4000
1002 1200 12000
1050 500 6500
Ex 5. Student Details Database
Keywords Table
course_code keyword
BCDE103 database
BCDE103 SQL
BCDE101 programming

BCDE101 Python

Staff Table
staff_id staff_first_name staff_last_name
88765 Chris Bartlett

99887 Rob Oliver


89898 Someone Else

Student Table
student_id first_name last_name
12345 Bob Brown
34568 Jane Smith

Student Result Table


student_id course_code course_semester
12345 BCDE103 2022-S1
34568 BCDE101 2022-S1
34568 BCDE101 2022-S2

Teaching Allocation Table


staff_id course_code course_semester
88765 BCDE103 2022-S1
99887 BCDE103 2022-S1
89898 BCDE101 2022-S1
89898 BCDE101 2022-S2

Course Table
code name
BCDE103 Database
BCDE101 Programming
address
10 Main Rd
100 North Rd

grade
A+
D
B
Ex 5. Student Details Database
Keywords Table
course_code (PKey) keyword (PKey)
BCDE103 database
BCDE103 SQL
BCDE101 programming
BCDE101 Python

Staff Table
staff_id (PKey) staff_first_name
88765 Chris

99887 Rob
89898 Someone

Student Table
student_id (PKey) first_name
12345 Bob
34568 Jane

Student Result Table


student_id (PKey) (FKey) course_code (PKey) (FKey)
12345 BCDE103
34568 BCDE101
34568 BCDE101

Teaching Allocation Table


staff_id (PKey) (FKey) course_code (PKey) (FKey)
88765 BCDE103
99887 BCDE103
89898 BCDE101
89898 BCDE101

Course Table
code (PKey) name
BCDE103 Database
BCDE101 Programming
staff_last_name
Bartlett

Oliver
Else

last_name address
Brown 10 Main Rd
Smith 100 North Rd

course_semester (PKey) grade


2022-S1 A+
2022-S1 D
2022-S2 B

course_semester (PKey)
2022-S1
2022-S1
2022-S1
2022-S2

You might also like