Assignment 5: E-R Diagrams, Weak Entity Sets, and SQL Exercises

1. An E-R diagram can be viewed as a graph. What do the following mean in terms of the structure of an enterprise schema?

a) The graph is disconnected.

b) The graph has a cycle.

3. We can convert any weak entity set to a strong entity set by simply adding appropriate attributes. Why, then, do we have weak entity sets?

4. SQL exercise:

a) Consider the following database:

i. Find ID and name of each employee who lives in the same city as the location of the company for which the employee works.

Select employee. ID, employee person_name 
from employee e 
join works w on e.ID-w.ID 
join company c on w.company_name - c.company_name 
where c.city = ecity

ii. Find ID and name of each employee who lives in the same city and on the same

street as does her or his manager.

Select employee.ID, employee.person_name 
from employee e 
join manages m on e. ID - m.ID 
where e.city = m.city and  e.street - m.street

iii. Find ID and name of each employee who earns more than the average salary of all

employees of her or his company.

select employee.ID, employee.person_name 
from employee e 
join manages m on e. ID - m.ID 
where e.city = m.city and e.street - m.street

b) Consider the following SQL query that seeks to find a list of titles of all courses taught in

Spring 2017 along with the name of the instructor.

select name, title 
from instructor 
natural join teaches 
natural join section 
natural join course 
where semester = 'Spring' and year = 2017 

What is wrong with this query?