0% found this document useful (0 votes)
18 views

01_1_Introduction_databases_Ex.docx

Uploaded by

amiina.elha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

01_1_Introduction_databases_Ex.docx

Uploaded by

amiina.elha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Exercises on Introduction databases

Exercise 1
In the information requirement below, you can see which employees are
working on which projects and how many hours they have already spent
per project.

Suppose you need to realize this information need in a relational model.


a. Determine the necessary tables of PK and FKs.
b. Draw the ERD.

Exercise 2

a. In the tables of the database below, designate the primary keys


(PK). Also designate the foreign keys (FK) and indicate what they
refer to.
b. Also draw the ERD.

DEPARTMENTS =(deptcode, deptname, deptaddress, depttel)

EMPLOYEES= (teacher_id,last_name,first_name,birth_date,degree,
Function_code)

EMP_DEPTS= (Teacher_id, deptcode, hours)

LECTURER_TASKS = ( Teacher_id, deptcode, course_code)

FUNCTIONS= (function_code, function_desc)

COURSES= (course_code, course_desc)


The DEPARTMENTS table provides the code, name, and coordinates of the
departments within the college.

The EMPLOYEES table lists the staff members within the college. These
employees may be lecturers, coordinators, heads of training, heads of ICT
services, deputy heads of departments or heads of departments. An
employee has only one function within the college. So, for example, a
lecturer cannot be a coordinator.

The table EMP_DEPTS shows which employee works in which department


and how many hours they work in that department. An employee can
work in multiple departments.

The table LECTURER_TASKS displays for instructors which subjects they


teach in which departments. A lecturer can teach multiple subjects in
multiple departments.

The table FUNCTIONS gives an overview of the functions exercised within


the college.

The COURSES table lists the courses taught within the college.

Exercise 3
a. In the tables of the database below, designate the primary keys
(PK). Also designate the foreign keys (FK) and indicate what they
refer to.
b. draw the ERD.

Database PROJECTS

EMPLOYEES = (employee_id, name, address, dept_id)

TRAVEL_REQUESTS = ( employee_id, request_date, destination,


travel_date, duration)

DEPARTMENTS= (dept_id , deptname)

PROJECTS = ( project_id, start_date, end_date, responsible_dept,


sponsor_dept, budget, description)

ASSIGNMENTS = ( project_id, employee_id, task, start_date, end_date)

TIMESHEETS= (project_id, employee_id, work_date, hours, overtime)


The table EMPLOYEES contains the classic personnel data of all
employees.
Employee_id : unique number for each staff member
Dept_id : Department code of the department where the staff
member works
Each employee belongs to one department.

The TRAVEL_REQUESTS table contains travel requests submitted by staff


members.
Request_date : date when the request is submitted
destination : place to which the employee wishes to travel
travel_date : date of departure
duration: : number of days the employee wishes to stay at the
destination
A person can only submit one travel request per day. However, during the
course of the year, one person can submit multiple travel requests.

The table DEPARTMENTS contains the departments within the company


Dept_id : unique code used within the company to
identify a department
deptname : official name for the department

The PROJECTS table contains projects that are either developed internally
for the company or are performed for external customers.
Project_id : identification of the project
start_date : date when the project is started
end_date : day following the date when the project ends.
responsible_dept : code of the department responsible for the
implementation of the project
sponsor_dept : code of the department responsible for the
financing of the project
budget : budgeted costs for the project
description : Short description of the project
The ASSIGNMENTS table shows the composition of the project groups.
This also includes the period of time the employee will be involved in the
project.
Project_id : identification of the project
Employee_id : identification of the employee
task : the function that the employee performs within the
project
start_date : first day of the period in which the employee is working
on the project
end_date : day following the last working day of the employee on
this project, as long as an employee is still collaborating
on a project, end date is not filled in!
An employee can be involved in multiple project groups.
In each project group, he/she can only do one task.

The TIMESHEETS table contains time sheets that record how many hours
a particular employee spent on a particular project on a particular date.
Only if the hours have been performed, a row is added to this table.
Note : no overtime can be recorded if no hours have been worked.
Work_date : date the work was performed
hours : Number of hours and minutes spent during normal working
hours
overtime : Number of hours and minutes spent outside normal working
hours
Per day, an employee can complete only one time sheet for a given
project.
Exercise 4
a. In the tables of the database below, designate the primary keys (PK).
Also designate the foreign keys (FK) and indicate what they refer to.
b. Draw the ERD of this database.

Database COURSES

DEPARTMENTS = (department_id, department_name,location,


manager_id)

EMPLOYEES= (employee_id, name, position, manager_id, birth_date,


salary, commission, department)

GRADES = (grade_id,lower_limit,upper_limit)

COURSES = (course_id,course_description,type,duration)

COURSE_SESSIONS = (course_id,Start_date, lecturer,location)

ENROLLMENTS = (trainee, course,start date,evaluation)

DEPARTMENTS contains the departments within the company.


department_id is a unique number for the department.
manager_id is the mnr of the head of the respective department
EMPLOYEES includes an overview of the employees within the company
Employee_id is a unique number that identifies an employee
manager_id is the employee of the manager of the employee in
question
commission is the commission rate (only applicable to sellers)
department contains the department_id of the department where
the employee works.
PAY_GRADES contains the pay scales
grade_id is a unique number per pay scale
COURSES contains information on all courses taught within the company
by employees from the company.
course_id is a unique identifier for a course
duration shows how many days the course is given
COURSE_SESSIONS contains the course sessions. Thus, a course can be
taught multiple times by the same or different instructor.
Instructor=employee.
No 2 sessions of a particular course can begin on the same day.
course_id contains the course code
lecturer contains the mnr of the staff member teaching that course
session.
ENROLLMENTS contains employee registrations for course sessions taught
by other employees.
trainee contains the employee_id of the trainee
course contains the course code
Exercise 5

The Enterprise database provides information about a company's


departments, as well as employees, family members, department
locations, projects, and which employees work on which projects.
The table DEPARTMENTS
The company is divided into departments.
Each department has a unique department number and name.
For each department, it stores who the manager is (EMPLOYEE_ID). This
manager is obviously an employee of the company. MANAGER_ID is therefore a
foreign key to EMPLOYEE_ID from the table EMPLOYEES.
A record is also kept of the date he/she became manager of this department.

The table LOCATIONS

A department may be located in one or more locations.


The table LOCATIONS contains the location information. Since a department can
be located in several locations, the key of this table is composed of
DEPARTMENT_ID and LOCATION.
DEPARTMENT_ID is a foreign key to DEPARTMENT_ID from the table
DEPARTMENTS.
The table EMPLOYEES

This table contains all information about employees.


Each employee has a unique number (EMPLOYEE_ID).
He works in one department. DEPARTMENT_ID is a foreign key to
DEPARTMENT_ID from DEPARTMENTS.
An employee has a chief (MANAGER_ID). This chief is also an employee.
Therefore, MANAGER_ID is a foreign key to EMPLOYEE_ID. We speak of a
recursive relationship here because the foreign key refers to the primary key of
the same table.
The table PROJECTS

This table lists all the projects carried out by the company.
Each project has a unique project number .
A project has a particular location and is monitored by a particular department.
DEPARTMENT_ID is a foreign key to DEPARTMENT_ID of the table
DEPARTMENTS.

The TASKS table

This table keeps track of which employee is working on which project and how
many hours they have already spent on the project.
Since an employee can work on multiple projects, the primary key of this table
consists of the combination EMPLOYEE_ID and PROJECT_ID.
EMPLOYEE_ID is foreign key to EMPLOYEE_ID from EMPLOYEES and PROJECT_ID
is foreign key to PROJECT_ID from PROJECTS.
The table FAMILY_MEMBERS

An employee may have zero, one or more family members.


Information about these family members is maintained in the FAMILY_MEMBERS
table.
The table keeps track of a family member's name, gender, date of birth, and
ralation to the employee (partner, son, daughter).
Since an employee can have multiple family members, EMPLOYEE_ID and NAME
together form the primary key of the table.
EMPLOYEE_ID is foreign key to EMPLOYEE_ID from EMPLOYEES.

Requested:
a. Indicate the PK and FKs for each table.
b. Set up the ERD from the enterprise database
c. Answer the questions below:
- Can a department be led by multiple department heads?
- Can an employee be assigned to multiple departments?
- Can there be a department without employees?
- Can there be a department without a department head?
- Can there be an employee without an assigned department?
- Can there be a manager without employees?
- Are there employees without a manager?
d. The contents of the table departments is currently as follows:

Suppose the table of employees includes the following row:

For each of the following operations, indicate whether the dekey


constraint, entity integrity constraint, or referential integrity constraint
is violated?

i. We are adding a new department. The name is 'Research', the


manager_id is '999666666', but the department_is is not yet entered.
ii. It was agreed to give the newly added department the number 1.
iii. We want to delete in the table departments the row concerning
department 3.
iv. we change for employee '999555555' the department_id to 7.
v. We change for employee '999555555' the department_id to 50.
vi. We change for employee '999555555' the department_id to a null
value.

You might also like