Professional Documents
Culture Documents
CH 02
CH 02
2. Define the following terms and give an example for each term: an attribute, the
domain of an attribute, a relation schema, a relation, n-tuple, degree of a relation, a
relationship, a relation instance (state), a relational database schema, a relational
database state, integrity constraints.
- Attribute (thuộc tính): trong 1 relation thì nó là 1 cột. Nó cho biết 1 thuộc tính
của đối tượng. Ví dụ: Trong 1 table SINHVIEN có 3 cột MSSV, Name,
DateofBirth là 3 attribute.
- Domain of an attribute: Tập hợp các giá trị được phép nhận của cột đó ( thuộc
tính đó). Ví dụ: Trong Table Score_SV, cột (thuộc tính) điểm giá trị sẽ được
nhận chỉ từ [0.0;10.0] (hệ 10) thôi.
- Relation schema: tập tất cả các thuộc tính có trong quan hệ. Lược đồ quan hệ
thường được viết dưới dạng:
<tên quan hệ>(danh sách các thuộc tính)
Ví dụ: SINHVIEN(MaSV, HoTen, NgaySinh, Diachi) cho biết Table tên
SINHVIEN có 4 thuộc tính: MaSV, HoTen, NgaySinh, Diachi. Trong đó
MaSV là primary key.
- Relation: một quan hệ là một bảng chứa dữ liệu bao gồm nhiều cột và nhiều
dòng. Dữ liệu trong một quan hệ phải thỏa các ràng buộc liên quan tới quan hệ
đó. Mỗi cột được gọi là một thuộc tính (attribute) hay một trường (field) của
quan hệ. Mỗi dòng được gọi là một bộ (tuple) hay mẫu tin/ bản ghi (record).
Ví dụ: Quan hệ SINHVIEN là 1 Table SINHVIEN. Ta định nghĩa 4
cột:MSSV, Name,NgaySinh, Address là 4 attribute. Mỗi dòng của Relation là
1 đối tượng ví dụ như:
MSSV Name NgaySinh Address
21162020 Trương Trọng 24/04/2003 2 VVN
.. …. …. …
Exercises.
1. Given one possible database state for the COMPANY relational database schema as
follows:
- Suppose that each of the following Update operations is applied directly to the database
state shown above. Discuss all integrity constraints violated by each operation, if any, and
the different ways of enforcing these constraints.
(Hỏi chèn 1 dòng vào có bị vi phạm ràng buộc gì hay không? Cách khắc phục)
- Which of the following operations are not correct? Why? Show the results of the
correct operations
(Phép chiếu – Xem trước chương 3 thì làm được. Còn không thì bỏ lại để qua tết học
rồi làm luôn).
a. ΠSsn, Fname, Lname, Salary(Employee)
b. σ Sex = F and Salary > 30000 (Employee)
c. σ Sex = F and Salary > 30000 (ΠSsn, Fname, Lname, Salary(Employee))
d. ΠSsn, Fname, Lname, Salary (σSex = F and Salary > 30000(Employee))
e. Department X Dept_Location
f. Department |X| Dept_Location
g. Compare the results of question e and f
h. Employee – Dependent
i. ΠSsn(Employee) - ΠEssn(Dependent)
j. σ Sex = F and Salary > 30000 (Employee) σSex = M and Salary < 30000(Employee)
k. ΠSsn(σDno=5(Employee)) Ssn(ΠEssn(σPno =1(Works_on)))
l. Explain the sense of the result of question j and k.