You are on page 1of 3

Exercide 4

1. Consider the employee database of Figure 2.1. Give an expression in the relational
algebra to express each of the following queries:

employee (person name, street, city)

works (person name, company name, salary)

company (company name, city)

a. Find the ID and name of each employee who works for “BigBank”.

b. Find the ID, name, and city of residence of each employee who works for

“BigBank”.

c. Find the ID, name, street address, and city of residence of each employee who

works for “BigBank” and earns more than $10000.

d. Find the ID and name of each employee in this database who lives in the same

city as the company for which she or he works.

a.
Π perso n ( σ city=BigBank ( company ) ⊳ ⊲company .compan y
name name =works .compan y name ( works ) ⊳ ⊲works . person name =employee. person name ( employee ))

b.
Π person name ,city (σ city=BigBank ( company ) ⊳ ⊲company .company name =works . company name ( works ) ⊳ ⊲works . person name =employee. person name ( employee ))

c.
Π person name , street , city (σ city=BigBank ⋀ salary >$ 10000 ( company ) ⊳ ⊲company . company name =works .company name ( works ) ⊳ ⊲works . person name =employee . personna

d. Π person (σ city=city ( company ) ⊳ ⊲company . city=employee .city ( employee ) )


name
2. List two reasons why null values might be introduced into a database.
- Giá trị null không có phân loại dữ liệu, do đó có thể được chèn vào bất kỳ cấu trúc dữ
liệu và bất kỳ cơ sở dữ liệu nào.
- Giá trị null chỉ chiếm rất ít dung lượng bộ nhớ nên chúng có thể hữu ích khi tối ưu hóa
cơ sở dữ liệu.
3. Discuss the relative merits of imperative, functional, and declarative languages
- Ngôn ngữ mệnh lệnh sử dụng một chuỗi các câu lệnh để xác định cách đạt được một
mục tiêu nhất định. Các câu lệnh này được cho là thay đổi trạng thái của chương trình khi
mỗi câu lệnh được thực thi lần lượt.

- Ngôn ngữ chức năng: mô hình lập trình chức năng được tạo ra một cách rõ ràng để hỗ
trợ một cách tiếp cận chức năng thuần túy để giải quyết vấn đề. Lập trình hàm là một
dạng của lập trình khai báo.

- Ngôn ngữ chức năng là một danh mục con của ngôn ngữ mệnh lệnh.

- Ngôn ngữ khai báo, còn được gọi là phi thủ tục hoặc cấp rất cao, là ngôn ngữ lập trình
trong đó (lý tưởng là) một chương trình chỉ định những gì sẽ được thực hiện hơn là cách
thực hiện. Hai loại ngôn ngữ khai báo phổ biến là ngôn ngữ logic và ngôn ngữ chức năng.

 Ngôn ngữ chức năng là một dạng của ngôn ngữ khai báo

4. Write the following queries in relational algebra, using the university schema.
classroom(building, room number, capacity)
department(dept name, building, budget)
course(course id, title, dept name, credits)
instructor(ID, name, dept name, salary)
section(course id, sec id, semester, year, building, room number, time slot id)
teaches(ID, course id, sec id, semester, year)
student(ID, name, dept name, tot cred)
takes(ID, course id, sec id, semester, year, grade)
advisor(s ID, i ID)
time slot(time slot id, day, start time, end time)
prereq(course id, prereq id)
Figure 2.5 Schema of the university database.
a. Find the ID and name of each instructor in the Physics department.
b. Find the ID and name of each instructor in a department located in the building
“Watson”.
c. Find the ID and name of each student who has taken at least one course in the “Comp.
Sci.” department.
d. Find the ID and name of each student who has taken at least one course section in the
year 2018.
e. Find the ID and name of each student who has not taken any course section in the year
2018.

a. Π ID, name (σ dept =Physics ( instructor ) )


name

b. Π ID, name (σ building =Watson ( department ) ⊳ ⊲department . dept name =instructor .dept name ( instructor ))

c. Π ID, name (σ dept =Com. Sci


name
( course ) ⊳ ⊲ course. dept name =student . dept name ( student ) )

d. Π ID, name ¿
e. Π ID, name ¿

You might also like