Đề cương câu hỏi lý thuyết ôn tập chương 2 môn Cơ sở dữ liệu | Đại học Sư phạm Kỹ thuật Thành phố Hồ Chí Minh

Đề cương câu hỏi lý thuyết ôn tập chương 2 môn Cơ sở dữ liệu của Đại học Sư phạm Kỹ thuật Thành phố Hồ Chí Minh với những kiến thức và thông tin bổ ích giúp sinh viên tham khảo, ôn luyện và phục vụ nhu cầu học tập của mình cụ thể là có định hướng ôn tập, nắm vững kiến thức môn học và làm bài tốt trong những bài kiểm tra, bài tiểu luận, bài tập kết thúc học phần, từ đó học tập tốt và có kết quả cao cũng như có thể vận dụng tốt những kiến thức mình đã học vào thực tiễn cuộc sống. Mời bạn đọc đón xem!

 

lOMoARcPSD|36625228
CÂU HỎI ÔN TẬP CHƯƠNG 2
1. Quan hệ là gì?
- bảng chứa dữ liệu bao gồm nhiều cột 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ệ đó
2. Mỗi cột trong một quan hệ còn được gọi là gì?
- Được gọi là một thuộc tính (attribute) hay một trường (field) của quan hệ
3. Mỗi dòng trong một quan hệ còn được gọi là gì?
- Được gọi là một bộ (tuple) hay mẫu tin/ bản ghi (record)
Ex: Quan hệ SINHVIEN
4. Ràng buộc toàn vẹn là gì?
Ràng buộc toàn vẹn là một điều kiện bất biến không được vi phạm trong một CSDL.
Trong một CSDL, luôn luôn tồn tại rất nhiều mối liên hệ ảnh hưởng qua lại lẫn nhau
giữa các thuộc tính của mối quan hệ, giữa các bộ giá trị trong một quan hệ giữa các
thuộc tính của các bộ giá trị trong các quan hệ với nhau. Các mối quan hệ phụ thuộc lẫn
nhau này chính những điều kiện bất biến tất cả các bộ của những quan hệ liên
quan trong sở dữ liệu đều phải thỏa mãn bất thời điểm nào. Ràng buộc toàn vẹn
được gọi các quy tắc quản (Rules) được áp đặt lên trên các đối tượng của thế giới thực.
5. Các quan hệ phải có ràng buộc toàn vẹn để làm gì?
-Trong một CSDL, ràng buộc toàn vẹn được xem như một công cụ để diễn đạt ngữ nghĩa
của sở dữ liệu đó. Trong suốt quá trình khai thác sở dữ liệu, các RBTV đều phải được
thỏa mãn bất thời điểm nào nhằm đảm bảo cho CSDL luôn luôn trạng thái an toàn
và nhất quán về dữ liệu
6. Miền giá trị (MGT) của một thuộc tính là gì?
-Là một tập giá trị mà một thuộc tính có thể nhận
lOMoARcPSD|36625228
7. Lược đồ quan hệ là gì?
-Lược đồ quan hệ (Relation schema): tập hợp tất cả các thuộc tính có trong quan hệ.
8. Biểu diễn nào dưới đây là lược đồ quan hệ
a. Q(A, B, C)
b. Q ß A, B, C
c. Q{A, B, C}
d. Cả 3 câu trên đều đúng
9. Thể hiện/ tình trạng của một quan hệ là gì?
- Tập hợp tất cả các bộ của một quan hệ tại một thời điểm
10. Cơ sở dữ liệu (CSDL) quan hệ là gì?
- CSDL quan hệ(Relational database) một tập các quan hệ liên quan với nhau vềmột
lĩnh vực cụ thể.
11. Lược đồ cơ sở dữ liệu (CSDL) quan hệ là gì?
- Lược đồ CSDL quan hệ (relational database schema): một tập các ợc đồ quan hệ
cóliên quan với nhau về một lĩnh vực cụ thể.
12. Siêu khóa của một lược đồ quan hệ Q(R) là gì?
- Một siêu khóa một khóa bản của bất k mối quan hệ. được định nghĩa làmột
khóa có thể xác định tất cả các thuộc tính khác trong một mối quan hệ
13. Trong một quan hệ Chỉ có duy nhất 1 siêu khóa là đúng hay sai
Sai
14. Một siêu khóa trong một quan hệ thể bao gồm nhiều hơn số thuộc tính
trongmột quan hệ là đúng hay sai?
Sai
15. Phát biểu nào dưới đây sai:
a. Số thuộc tính trong siêu khóa là tập con của tập thuộc tính trong quan hệ
b. Tập cha của siêu khóa cũng chính là siêu khóa
lOMoARcPSD|36625228
c. Một tập con bất kỳ của siêu khóa cũng là siêu khóa
d. Cả 3 câu trên đều đúng
16. Cho Q(A, B, C, D, E) có siêu khóa là {A, B, C}. Phát biểu nào dưới đây là sai:
a. {A, B, C, D} là siêu khóa
b. {A, B, C, D, E} là siêu khóa
c. Cả 2 câu a, b đều đúng
d. Cả 2 câu a, b đều sai
17. Khóa ứng viên (candidate key) của một quan hệ là gì?
Siêu khóa k được gọi là khóa ứng viên nếu k là tập nhỏ nhất
Trong tập hợp các thuộc tính của một bảng, có thể có nhiều thuộc tính có thể
dùng được làm khóa chính. Các thuộc tính đó được gọi là khóa dự tuyển.
18. Phát biểu nào sau đây đúng
a. Khóa ứng viên là khóa có thể được chọn làm khóa chính cho một quan hệ
b. Mỗi quan hệ chỉ có duy nhất một khóa ứng viên
c. Cả a và b đều đúng
d. Cả a và b đều sai
19. Khóa chính (primary key) của một quan hệ là gì?
- Khóa chính (primary key): Một trong các khóa ứng viên sđược chọn làm khóachính
cho quan hệ.
20. Mỗi quan hệ chỉ có duy nhất 1 khóa chính là đúng hay sai?
Sai
21. Cho Q1(A, B, C) và Q2(D, A). Phát biểu nào dưới đây là đúng
a. Thuộc tính Q2.A là khóa ngoại trong Q2
b. Q1 được gọi là quan hệ được tham chiếu và Q2 được gọi quan hệ thamchiếu
c. Thuộc tính Q2.A tham chiếu qua Q1.A
lOMoARcPSD|36625228
d. Cả 3 câu trên đều đúng
22. Cho Q1(A, B, C) và Q2(D, B). Phát biểu nào dưới đây là đúng
a. Q2.B thể khóa ngoại tham chiếu qua Q1.B nếu Q1.B ràng buộc unique
b. Q2.B là khóa ngoại tham chiếu qua Q1.B nếu Q1.B có ràng buộc not null
c. Cả 2 câu a, b đều đúng
d. Cả 2 câu a, b đều đúng
23. Phát biểu nào dưới đây đúng
a. Khóa ngoại trong mô hình quan hệ biểu diễn mối kết hợp giữa 2 quan hệ
b. Ràng buộc về khóa ngoại còn gọi là ràng buộc tham chiếu
c. Cả 2 câu a, b đều đúng
d. Cả 2 câu a, b đều đúng
24. Giải thích ràng buộc tham chiếu nghĩa giữa Q1(A, B, C) và Q2(D, A)
- Q1 được gọi là quan hệ được tham chiếu và Q2 được gọi là quan hệ tham chiếu
- Thuộc tính Q2.A là khóa ngoại trong Q2
- Thuộc tính Q2.A tham chiếu qua Q1.A
25. Một thuộc tính có ràng buộc unique nghĩa là gì?
Ràng buộc unique (duy nhất): mỗi giá trị trong cột ràng buộc này phải duy
nhất trong cột đó.
26. Một thuộc tính có ràng buộc not null nghĩa là gì?
Các ô trong cột có ràng buộc này bắt buộc phải có giá trị khác Null.
27. Một thuộc tính có ràng buộc khóa chính nghĩa là gì?
Ràng buộc khóa chính: các giá trị là khóa chính phải là unique và not null.
28. Miền giá trị của một thuộc tính nghĩa có phải là một ràng buộc áp đặt lên dữliệu
của thuộc tính đó không?
lOMoARcPSD|36625228
Miền giá trị của một thuộc tính nghĩa là một ràng buộc áp đặt lên dữ liệu của thuộc
tính đó.
29. Các hiệu sau |Sex|, Dom(Sex), MGT(Sex) hiệu o hiệu miền giá trịcủa
thuộc tính Sex.
MGT(Sex) ,Dom(Sex) là ký hiệu miền giá trị của thuộc tính Sex.
30. Cho NV(MaNV, Hoten, NgaySinh) PB(MaPB, TenPB, Matrph). Quy định:
mỗi phòng ban có 1 NV là trương phòng. Phát biểu nào dưới đây là đúng 2 lược
đồ quan hệ trên
a. MaNV có ràng buộc unique và not null
b. Có ràng buộc tham chiếu từ PB.Matrph sang NV.MaNV
c. Cả a và b đều sai
d. Cả a và b đều đúng
31. Trong một quan hệ, thứ tự các thuộc tính các bộ quan trọng không? Tạisao?
Trong một quan hệ, thứ tự các thuộc tính và các bộ không quan trọng. Về mặt toán
học, các phần tử thể xuất hiện tùy ý trong một tập hợp không làm thay đổi
bản chất của tập hợp đó, nên thứ tự hàng và cột không quan trọng.
ASSIGNMENT(GROUP)
Review questions
1. Describe the three-schema architecture.
lOMoARcPSD|36625228
- The external or view level, which includes a number of external schemas or user
viewsthat define how different users see the data in the database.
- The conceptual or logical level, which has a conceptual schema that describes
thestructure of the whole database for a community of users, and the relationships and
constraints among the data.
- The internal or physical level, which has an internal schema that describes the
physicalstorage structure of the database, and the access methods and indexes used to
optimize performance
2. Define the following terms and give an example for each term: an attribute,
thedomain 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): Attributes are the properties that define an entity. Ex:
ROLL_NO, NAME, ADDRESS
The domain of attribute: Every attribute has some predefined value and scope which
is known as attribute domain
Ex: MGT(Job)={“Teacher”; “Student”}
lOMoARcPSD|36625228
Relation schema: A relation schema defines the structure of the relation and
represents the name of the relation with its attributes.
Ex; STUDENT (ROLL_NO, NAME, ADDRESS, PHONE, and AGE) is the
relation schema for STUDENT. If a schema has more than 1 relation, it is called
Relational Schema.
Tuple: Each row in the relation is known as a tuple. The above relation contains 4
tuples, one of which is shown as:
called a relation instance. Table 1 shows the relation instance of STUDENT at a
particular time. It can change whenever there is an insertion, deletion, or update in
the database.
Ex: The instance of relation student consists of 12 rows corresponding to 12
students.
Degree: The number of attributes in the relation is known as the degree of the
relation. The STUDENT relation defined above has degree 5. Ex:The STUDENT
relation defined above has degree 5.
A relational database state is sometimes called a relational database instance.
However, as we mentioned earlier, we will not use the term instance since it also
applies to single tuples.
Ex: Set of relation states DB={r1,r2,..., rm} Each r(i) is a state of R(i) and such
that the r(i) relation states satisfy integrity constraints specified in IC.
A relational database schema is a set of relation schemas and a set of integrity
constraints
Ex: A bakery schema that has tables for ingredients, recipes, types of baked goods,
prices or customer information.
Integrity constraints: are a set of rules. It is used to maintain the quality of
information, ensure that the data insertion, updating, and other processes have to be
performed in such a way that data integrity is not affected. Thus, integrity constraint
is used to guard against accidental damage to the database.
Ex : A blood group must be ‘A’ or ‘B’ or ‘AB’ or ‘O’ only (can not have any other
values else)
3. Why are tuples in a relation not ordered?
1
RAM
DELHI
9455123451
18
Relation Instance
The set of tuples of a relation at a particular instance of time is
lOMoARcPSD|36625228
Order of tuples is irrelevant (tuples may be stored in an arbitrary order)
Mathematically, elements of a set have no order among them; hence, tuples in a
relation do not have any particular order. In other words, a relation is not sensitive
to the ordering of tuples.
4. Why are duplicate tuples not allowed in a relation?
- Because the body of a relation is a set (a set of tuples) and sets in mathematics
don’tcontain duplicate elements.
5. What is the difference between a key and a superkey?
A key is a single attribute or a combination of two or more attributes of an entity set
which is used to identify one or more examples (rows) of the set (table). It is a
minimal combination of attributes.
A super key is a set of one or more attributes in which, taken collectively, permits
us to identify uniquely a tuple within the relation.
6. Discuss the entity integrity and referential integrity constraints. Why is
eachconsidered important?
The entity integrity constraint states that no primary key value can be NULL. This
is because the primary key value is used to identify individual tuples in a relation.
Having NULL values for the primary key implies that we cannot identify some
tuples. Entity integrity ensures that every row in a table is unique and can be
referenced.
The referential integrity constraint is specified between two relations and is used
to maintain the consistency among tuples in the two relations. Informally, the
referential integrity constraint states that a tuple in one relation that refers to another
relation must refer to an existing tuple in that relation. Referential integrity ensures
thay only a valid foreign key can be assigned to a table.
Both are important because they help to ensure that data is accurate and consistent,
that the relationships between tables are maintained.
Exercises.
1. Given one possible database state for the COMPANY relational database schema
as follows:
lOMoARcPSD|36625228
- 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.
lOMoARcPSD|36625228
(Giả sử rằng mỗi thao tác Cập nhật sau đây được áp dụng trực tiếp vào trạng thái cơ sở dữ
liệu được hiển thị trên. Thảo luận về tất cả các ràng buộc toàn vẹn bị vi phạm bởi mỗi
thao tác, nếu có, và các cách khác nhau để thực thi các ràng buộc này.
a. Insert <‘Robert’, ‘F’, Scott’, ‘943775543’, ‘1972-06-21’, ‘2365 Newcastle Rd,Bellaire,
TX’, M, 58000, ‘888665555’, 1> into EMPLOYEE. -This insertion satisfies all
constraints, so it is acceptable
b. Insert <‘ProductA’, 4, ‘Bellaire’, 2> into PROJECT
-This insertion violates the referential integrity constraints specified on Dnum because no
DEPARTMENT tuple exists with DNUMBER = 2 A way to enforce this constraint is to
insert a DEPARTMENT tuple with Dnumber=2 and then perform the above insertion
operation. Else, change the DNUMBER of the above tuple to valid Dnumber such as 5, 4
or 1.
c. Insert <‘Production’, 4, ‘943775543’, ‘2007-10-01’> into DEPARTMENT
-This insertion violates the key constraint because another tuple (i.e Administration) with
the same Dnumber already exists A way to enforce this constraint is to change the Dnumber
for Production to one that is not being used in the Department relation
lOMoARcPSD|36625228
d. Insert <‘677678989’, NULL, ‘40.0’> into WORKS_ON
-This insertion violates the entity integrity constraint (null for the primary key Pno) It also
violates referential integrity specified on SSN because no EMPLOYEE tuple exists where
SSN = ‘677678989’ A way to enforce this constraint is to change the null value to valid
Pno, also insert an employee tuple with SSN = ‘677678989’ and then perform the above
insert operation. Another option to enforce this constraint is to change the ESSN to a valid
SSN from the EMPLOYEE table such as 666884444
e. Insert <‘453453453’, ‘John’, ‘M’, ‘1990-12-12’, ‘spouse’> into DEPENDENT.
-This insertion satisfies all constraints, so it is acceptable
f. Delete the WORKS_ON tuples with Essn = ‘333445555’
-This deletion is acceptable
g. Delete the EMPLOYEE tuple with Ssn = ‘987654321’
-This deletion is not acceptable because tuples in EMPLOYEE, DEPARTMENT,
WORKS_ON and DEPENDENT refer this tuple. Hence, if the tuple is deleted, referential
integrity violations will result A way to enforce this constraint is to delete tuples that
reference the tuple that is being deleted. Another option is to modify the referencing
attribute to another value such as null or valid tuple value
h. Delete the PROJECT tuple with Pname = ‘ProductX’
-This deletion is not acceptable because tuples in WORKS_ON refer to this tuple. Hence
referential integrity violations will result. A way to enforce this constraint is to delete tuples
that reference the tuple that is being deleted. Another option is to modify the referencing
attribute to another value such as null or valid tuple value
i. Modify the Mgr_ssn and Mgr_start_date of the DEPARTMENT tuple with Dnumber =5
to ‘123456789’ and ‘2007-10-01’, respectively.
-This modification satisfies all constraints, so it is acceptable
j. Modify the Super_ssn attribute of the EMPLOYEE tuple with Ssn = ‘999887777
to‘943775543’.
-This modification satisfies all constraints, so it is acceptable
k. Modify the Hours attribute of the WORKS_ON tuple with Essn = ‘999887777’ andPno
= 10 to ‘5.0’.
lOMoARcPSD|36625228
-This modification satisfies all constraints, so it is acceptable
- Which of the following operations are not correct? Why? Show the results of the
correct operations:
a. ΠSsn, Fname, Lname, Salary(Employee)
Câu lệnh này đúng. Đúng về cú pháp của lệnh chiếu và các cột Ssn, Fname, Lname, Salary đều có
trong bảng EMPLOYEE. Kết quả một bảng mới gồm 4 cột Ssn, Fname, Lname, Salary và tất cả
dữ liệu trong các dòng của 4 cột này.
b. σSex = F and Salary > 30000(Employee)
c. σSex = F and Salary > 30000 (ΠSsn, Fname, Lname, Salary(Employee))
Câu lệnh y đúng về pháp nhưng sai về logic phép chiếu trong ngoặc được thực
hiện trước cho ra kết quả một bảng gồm 4 cột Ssn, Fname, Lname, Salary. Sau đó
phép chọn được thực hiện trên bảng kết quả của phép chiếu với điều kiện Sex = F and
Salary > 30000. Nhưng trong bảng kết quả không có cột Sex.
d. ΠSsn, Fname, Lname, Salary (σSex = F and Salary > 30000(Employee))
Ssn
Fname
Lname
Salary
987654321
Jennifer
Wallace
43000
e. Department X Dept_Location
lOMoARcPSD|36625228
Dname
Dnumber
Mgr_ssn
Mgr_start_date
Dnumber
Dlocation
Research
5
333445555
1998-05-22
1
Houston
Research
5
333445555
1998-05-22
4
Stafford
Research
5
333445555
1998-05-22
5
Bellaire
Research
5
333445555
1998-05-22
5
Sugarland
Research
5
333445555
1998-05-22
5
Houston
Administration
4
987654321
1995-01-01
1
Houston
Administration
4
987654321
1995-01-01
4
Stafford
Administration
4
987654321
1995-01-01
5
Bellaire
Administration
4
987654321
1995-01-01
5
Sugarland
Administration
4
987654321
1995-01-01
5
Houston
Headquarters
1
888665555
1981-06-19
1
Houston
Headquarters
1
888665555
1981-06-19
4
Stafford
Headquarters
1
888665555
1981-06-19
5
Bellaire
Headquarters
1
888665555
1981-06-19
5
Sugarland
Headquarters
1
888665555
1981-06-19
5
Houston
f. Department |X| Dept_Location
Dname
Dnumber
Mgr_ssn
Mgr_start_date
Dlocation
Research
5
33344555
5
1998-05-22
Bellaire
Research
5
33344555
5
1998-05-22
Sugarland
Research
5
33344555
5
1998-05-22
Houston
lOMoARcPSD|36625228
Administration
4
98765432
1
1995-01-01
Stafford
Headquarters
1
88866555
5
1981-06-19
Houston
g. Compare the results of question e and f
Số lượng hàng và cột của câu e lớn hơn nhiều so với câu f. Câu e sử dụng
phép tính tích đề cạc, còn câu f sử dụng phép tính Natural Join . Nên câu e
có thể tồn tại các cặp trùng nhau
h. Employee Dependent
-Không trừ được bởi vì Employee và Dependent không cùng cấu trúc.
i. Π
Ssn
(Employee) - ΠE
ssn
(Dependent)
-Vì có cùng cấu trúc nên trừ được
Ssn
123456789
999887777
666884444
453453453
987987987
j. σSex = F and Salary > 30000(Employee) È σSex = M and Salary < 30000(Employee)
Fname
Minit
Lname
Ssn
Bdate
Address
Sex
Salary
Super_snn
Dno
Jennifer
S
Wallace
987654321
1941-
06-20
291 Berry,
Bellaire, TX
F
43000
888665555
4
lOMoARcPSD|36625228
Ahmad V
V
Jabbar
1969-03-29
196903-
29
980 Dallas,
Houston,
TX
M
25000
987654321
4
k. Π
Ssn
(σDno=5(Employee)) Ç rSsn(ΠEs
sn
(σPno =1(Works_on)))
Ssn
123456789
453453453
l. Explain the sense of the result of question j and k.
Ý nghĩa của kết quả 2 câu hỏi j và k là các phép hội hay phép giao chỉ có thể thực hiện
khi 2 quan hệ thỏa tương thích hội.
2. Given a University database as follows:
Consider the above figure. In addition to constraints relating the values of columns in one
table to columns in another table, there are also constraints that impose restrictions on
values in a column or a combination of columns within a table. One such constraint dictates
that a column or a group of columns must be unique across all rows in the table. For
lOMoARcPSD|36625228
example, in the STUDENT table, the Student_number column must be unique (to prevent
two different students from having the same Student_number).
- Identify the column or the group of columns in the other tables that must be uniqueacross
all rows in the table.
- Identify the primary key, foreign key in each relational schema.
- Specify the following queries on the University database schema:
a. Retrieve the student_number and the name of all students in the university.
Π Student_number, Name(STUDENT)
b. Retrieve the student_number and the name of all students in “Computer Science”major
Π Student_number, Name(σMajor= Computer Science(STUDENT))
c. Retrieve the prerequisite course number and course name of the course which hascourse
number “1111’’
Πprerequisite_number,course_number,course_name(σcourse_number=1111(COURSE|X|
PREREQUISITE))
d. Retrieve the section identifier, course number and course name of courses which
areopened in semester 1, year 2019
Πsection_identifier,course_number,course_name(σsemester=1andyear=2019(COURSE|
X| SECTION))
e. Retrieve the section identifier, course number and course name of courses which arenot
opened in semester 1, year 2019
Πsection_identifier,course_number,course_name(σsemester!=1 and year!
=2019(COURSE|X| SECTION))
f. Retrieve the section identifier, course number and course name of courses which
areopened in year 2018 or 2019.
Πsection_identifier,course_number,course_name(σyear=2018(COURSE|X| SECTION))
Πsection_identifier,course_number,course_name(σyear=2019(COURSE|X| SECTION))
g. Retrieve the section identifier, course number and course name of courses which
areopened in year 2018 and 2019.
Πsection_identifier,course_number,course_name(σyear=2018(COURSE|X| SECTION))
lOMoARcPSD|36625228
Πsection_identifier,course_number,course_name(σyear=2019(COURSE|X| SECTION))
| 1/17

Preview text:

lOMoARcPSD| 36625228
CÂU HỎI ÔN TẬP CHƯƠNG 2 1. Quan hệ là gì?
- Là 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ệ đó
2. Mỗi cột trong một quan hệ còn được gọi là gì?
- Được gọi là một thuộc tính (attribute) hay một trường (field) của quan hệ
3. Mỗi dòng trong một quan hệ còn được gọi là gì?
- Được gọi là một bộ (tuple) hay mẫu tin/ bản ghi (record) Ex: Quan hệ SINHVIEN
4. Ràng buộc toàn vẹn là gì?
Ràng buộc toàn vẹn là một điều kiện bất biến không được vi phạm trong một CSDL.
Trong một CSDL, luôn luôn tồn tại rất nhiều mối liên hệ ảnh hưởng qua lại lẫn nhau
giữa các thuộc tính của mối quan hệ, giữa các bộ giá trị trong một quan hệ và giữa các
thuộc tính của các bộ giá trị trong các quan hệ với nhau. Các mối quan hệ phụ thuộc lẫn
nhau này chính là những điều kiện bất biến mà tất cả các bộ của những quan hệ có liên
quan trong cơ sở dữ liệu đều phải thỏa mãn ở bất kì thời điểm nào. Ràng buộc toàn vẹn
được gọi là các quy tắc quản lý (Rules) được áp đặt lên trên các đối tượng của thế giới thực. 5.
Các quan hệ phải có ràng buộc toàn vẹn để làm gì?
-Trong một CSDL, ràng buộc toàn vẹn được xem như một công cụ để diễn đạt ngữ nghĩa
của cơ sở dữ liệu đó. Trong suốt quá trình khai thác cơ sở dữ liệu, các RBTV đều phải được
thỏa mãn ở bất kì thời điểm nào nhằm đảm bảo cho CSDL luôn luôn ở trạng thái an toàn
và nhất quán về dữ liệu 6.
Miền giá trị (MGT) của một thuộc tính là gì?
-Là một tập giá trị mà một thuộc tính có thể nhận lOMoARcPSD| 36625228 7.
Lược đồ quan hệ là gì?
-Lược đồ quan hệ (̣Relation schema): tập hợp tất cả các thuộc tính có trong quan hệ. 8.
Biểu diễn nào dưới đây là lược đồ quan hệ a. Q(A, B, C) b. Q ß A, B, C c. Q{A, B, C} d.
Cả 3 câu trên đều đúng 9.
Thể hiện/ tình trạng của một quan hệ là gì?
- Tập hợp tất cả các bộ của một quan hệ tại một thời điểm
10. Cơ sở dữ liệu (CSDL) quan hệ là gì?
- CSDL quan hệ(Relational database) là một tập các quan hệ có liên quan với nhau vềmột lĩnh vực cụ thể.
11. Lược đồ cơ sở dữ liệu (CSDL) quan hệ là gì?
- Lược đồ CSDL quan hệ (relational database schema): một tập các lược đồ quan hệ
cóliên quan với nhau về một lĩnh vực cụ thể.
12. Siêu khóa của một lược đồ quan hệ Q(R) là gì?
- Một siêu khóa là một khóa cơ bản của bất kỳ mối quan hệ. Nó được định nghĩa làmột
khóa có thể xác định tất cả các thuộc tính khác trong một mối quan hệ
13. Trong một quan hệ Chỉ có duy nhất 1 siêu khóa là đúng hay sai Sai
14. Một siêu khóa trong một quan hệ có thể bao gồm nhiều hơn số thuộc tính
trongmột quan hệ là đúng hay sai? Sai
15. Phát biểu nào dưới đây sai: a.
Số thuộc tính trong siêu khóa là tập con của tập thuộc tính trong quan hệ b.
Tập cha của siêu khóa cũng chính là siêu khóa lOMoARcPSD| 36625228 c.
Một tập con bất kỳ của siêu khóa cũng là siêu khóa d.
Cả 3 câu trên đều đúng
16. Cho Q(A, B, C, D, E) có siêu khóa là {A, B, C}. Phát biểu nào dưới đây là sai: a. {A, B, C, D} là siêu khóa b.
{A, B, C, D, E} là siêu khóa c.
Cả 2 câu a, b đều đúng d. Cả 2 câu a, b đều sai
17. Khóa ứng viên (candidate key) của một quan hệ là gì?
Siêu khóa k được gọi là khóa ứng viên nếu k là tập nhỏ nhất •
Trong tập hợp các thuộc tính của một bảng, có thể có nhiều thuộc tính có thể
dùng được làm khóa chính. Các thuộc tính đó được gọi là khóa dự tuyển.
18. Phát biểu nào sau đây đúng a.
Khóa ứng viên là khóa có thể được chọn làm khóa chính cho một quan hệ b.
Mỗi quan hệ chỉ có duy nhất một khóa ứng viên c. Cả a và b đều đúng d. Cả a và b đều sai
19. Khóa chính (primary key) của một quan hệ là gì?
- Khóa chính (primary key): Một trong các khóa ứng viên sẽ được chọn làm khóachính cho quan hệ.
20. Mỗi quan hệ chỉ có duy nhất 1 khóa chính là đúng hay sai? Sai
21. Cho Q1(A, B, C) và Q2(D, A). Phát biểu nào dưới đây là đúng a.
Thuộc tính Q2.A là khóa ngoại trong Q2 b.
Q1 được gọi là quan hệ được tham chiếu và Q2 được gọi là quan hệ thamchiếu c.
Thuộc tính Q2.A tham chiếu qua Q1.A lOMoARcPSD| 36625228 d.
Cả 3 câu trên đều đúng
22. Cho Q1(A, B, C) và Q2(D, B). Phát biểu nào dưới đây là đúng a.
Q2.B có thể là khóa ngoại tham chiếu qua Q1.B nếu Q1.B có ràng buộc unique b.
Q2.B là khóa ngoại tham chiếu qua Q1.B nếu Q1.B có ràng buộc not null c.
Cả 2 câu a, b đều đúng d.
Cả 2 câu a, b đều đúng
23. Phát biểu nào dưới đây đúng a.
Khóa ngoại trong mô hình quan hệ biểu diễn mối kết hợp giữa 2 quan hệ b.
Ràng buộc về khóa ngoại còn gọi là ràng buộc tham chiếu c.
Cả 2 câu a, b đều đúng d.
Cả 2 câu a, b đều đúng
24. Giải thích ràng buộc tham chiếu nghĩa giữa Q1(A, B, C) và Q2(D, A)
- Q1 được gọi là quan hệ được tham chiếu và Q2 được gọi là quan hệ tham chiếu
- Thuộc tính Q2.A là khóa ngoại trong Q2
- Thuộc tính Q2.A tham chiếu qua Q1.A
25. Một thuộc tính có ràng buộc unique nghĩa là gì?
Ràng buộc unique (duy nhất): mỗi giá trị trong cột có ràng buộc này phải là duy nhất trong cột đó.
26. Một thuộc tính có ràng buộc not null nghĩa là gì?
Các ô trong cột có ràng buộc này bắt buộc phải có giá trị khác Null.
27. Một thuộc tính có ràng buộc khóa chính nghĩa là gì?
Ràng buộc khóa chính: các giá trị là khóa chính phải là unique và not null.
28. Miền giá trị của một thuộc tính nghĩa có phải là một ràng buộc áp đặt lên dữliệu
của thuộc tính đó không? lOMoARcPSD| 36625228 •
Miền giá trị của một thuộc tính nghĩa là một ràng buộc áp đặt lên dữ liệu của thuộc tính đó.
29. Các ký hiệu sau |Sex|, Dom(Sex), MGT(Sex) ký hiệu nào là ký hiệu miền giá trịcủa thuộc tính Sex.
MGT(Sex) ,Dom(Sex) là ký hiệu miền giá trị của thuộc tính Sex.
30. Cho NV(MaNV, Hoten, NgaySinh) và PB(MaPB, TenPB, Matrph). Quy định:
mỗi phòng ban có 1 NV là trương phòng. Phát biểu nào dưới đây là đúng 2 lược đồ quan hệ trên a.
MaNV có ràng buộc unique và not null b.
Có ràng buộc tham chiếu từ PB.Matrph sang NV.MaNV c. Cả a và b đều sai d. Cả a và b đều đúng
31. Trong một quan hệ, thứ tự các thuộc tính và các bộ có quan trọng không? Tạisao?
Trong một quan hệ, thứ tự các thuộc tính và các bộ không quan trọng. Về mặt toán
học, các phần tử có thể xuất hiện tùy ý trong một tập hợp mà không làm thay đổi
bản chất của tập hợp đó, nên thứ tự hàng và cột không quan trọng. ASSIGNMENT(GROUP) Review questions 1.
Describe the three-schema architecture. lOMoARcPSD| 36625228
- The external or view level, which includes a number of external schemas or user
viewsthat define how different users see the data in the database.
- The conceptual or logical level, which has a conceptual schema that describes
thestructure of the whole database for a community of users, and the relationships and constraints among the data.
- The internal or physical level, which has an internal schema that describes the
physicalstorage structure of the database, and the access methods and indexes used to optimize performance 2.
Define the following terms and give an example for each term: an attribute,
thedomain 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): Attributes are the properties that define an entity. Ex: ROLL_NO, NAME, ADDRESS •
The domain of attribute: Every attribute has some predefined value and scope which is known as attribute domain
Ex: MGT(Job)={“Teacher”; “Student”} lOMoARcPSD| 36625228 •
Relation schema: A relation schema defines the structure of the relation and
represents the name of the relation with its attributes.
Ex; STUDENT (ROLL_NO, NAME, ADDRESS, PHONE, and AGE) is the
relation schema for STUDENT. If a schema has more than 1 relation, it is called Relational Schema. •
Tuple: Each row in the relation is known as a tuple. The above relation contains 4
tuples, one of which is shown as: 1 RAM DELHI 9455123451 18
Relation Instance : The set of tuples of a relation at a particular instance of time is
called a relation instance. Table 1 shows the relation instance of STUDENT at a
particular time. It can change whenever there is an insertion, deletion, or update in the database.
Ex: The instance of relation student consists of 12 rows corresponding to 12 students. •
Degree: The number of attributes in the relation is known as the degree of the
relation. The STUDENT relation defined above has degree 5. Ex:The STUDENT
relation defined above has degree 5. •
A relational database state is sometimes called a relational database instance.
However, as we mentioned earlier, we will not use the term instance since it also applies to single tuples.
Ex: Set of relation states DB={r1,r2,..., rm} Each r(i) is a state of R(i) and such
that the r(i) relation states satisfy integrity constraints specified in IC. •
A relational database schema is a set of relation schemas and a set of integrity constraints
Ex: A bakery schema that has tables for ingredients, recipes, types of baked goods,
prices or customer information. •
Integrity constraints: are a set of rules. It is used to maintain the quality of
information, ensure that the data insertion, updating, and other processes have to be
performed in such a way that data integrity is not affected. Thus, integrity constraint
is used to guard against accidental damage to the database.
Ex : A blood group must be ‘A’ or ‘B’ or ‘AB’ or ‘O’ only (can not have any other values else) 3.
Why are tuples in a relation not ordered? lOMoARcPSD| 36625228 •
Order of tuples is irrelevant (tuples may be stored in an arbitrary order) •
Mathematically, elements of a set have no order among them; hence, tuples in a
relation do not have any particular order. In other words, a relation is not sensitive to the ordering of tuples. 4.
Why are duplicate tuples not allowed in a relation?
- Because the body of a relation is a set (a set of tuples) and sets in mathematics
don’tcontain duplicate elements. 5.
What is the difference between a key and a superkey?
A key is a single attribute or a combination of two or more attributes of an entity set
which is used to identify one or more examples (rows) of the set (table). It is a
minimal combination of attributes. •
A super key is a set of one or more attributes in which, taken collectively, permits
us to identify uniquely a tuple within the relation. 6.
Discuss the entity integrity and referential integrity constraints. Why is eachconsidered important?
The entity integrity constraint states that no primary key value can be NULL. This
is because the primary key value is used to identify individual tuples in a relation.
Having NULL values for the primary key implies that we cannot identify some
tuples. Entity integrity ensures that every row in a table is unique and can be referenced. •
The referential integrity constraint is specified between two relations and is used
to maintain the consistency among tuples in the two relations. Informally, the
referential integrity constraint states that a tuple in one relation that refers to another
relation must refer to an existing tuple in that relation. Referential integrity ensures
thay only a valid foreign key can be assigned to a table. •
Both are important because they help to ensure that data is accurate and consistent,
that the relationships between tables are maintained. Exercises.
1. Given one possible database state for the COMPANY relational database schema as follows: lOMoARcPSD| 36625228
- 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. lOMoARcPSD| 36625228
(Giả sử rằng mỗi thao tác Cập nhật sau đây được áp dụng trực tiếp vào trạng thái cơ sở dữ
liệu được hiển thị ở trên. Thảo luận về tất cả các ràng buộc toàn vẹn bị vi phạm bởi mỗi
thao tác, nếu có, và các cách khác nhau để thực thi các ràng buộc này.
a. Insert <‘Robert’, ‘F’, ‘Scott’, ‘943775543’, ‘1972-06-21’, ‘2365 Newcastle Rd,Bellaire,
TX’, M, 58000, ‘888665555’, 1> into EMPLOYEE. -This insertion satisfies all
constraints, so it is acceptable
b. Insert <‘ProductA’, 4, ‘Bellaire’, 2> into PROJECT
-This insertion violates the referential integrity constraints specified on Dnum because no
DEPARTMENT tuple exists with DNUMBER = 2 A way to enforce this constraint is to
insert a DEPARTMENT tuple with Dnumber=2 and then perform the above insertion
operation. Else, change the DNUMBER of the above tuple to valid Dnumber such as 5, 4 or 1.
c. Insert <‘Production’, 4, ‘943775543’, ‘2007-10-01’> into DEPARTMENT
-This insertion violates the key constraint because another tuple (i.e Administration) with
the same Dnumber already exists A way to enforce this constraint is to change the Dnumber
for Production to one that is not being used in the Department relation lOMoARcPSD| 36625228
d. Insert <‘677678989’, NULL, ‘40.0’> into WORKS_ON
-This insertion violates the entity integrity constraint (null for the primary key Pno) It also
violates referential integrity specified on SSN because no EMPLOYEE tuple exists where
SSN = ‘677678989’ A way to enforce this constraint is to change the null value to valid
Pno, also insert an employee tuple with SSN = ‘677678989’ and then perform the above
insert operation. Another option to enforce this constraint is to change the ESSN to a valid
SSN from the EMPLOYEE table such as 666884444
e. Insert <‘453453453’, ‘John’, ‘M’, ‘1990-12-12’, ‘spouse’> into DEPENDENT.
-This insertion satisfies all constraints, so it is acceptable
f. Delete the WORKS_ON tuples with Essn = ‘333445555’ -This deletion is acceptable
g. Delete the EMPLOYEE tuple with Ssn = ‘987654321’
-This deletion is not acceptable because tuples in EMPLOYEE, DEPARTMENT,
WORKS_ON and DEPENDENT refer this tuple. Hence, if the tuple is deleted, referential
integrity violations will result A way to enforce this constraint is to delete tuples that
reference the tuple that is being deleted. Another option is to modify the referencing
attribute to another value such as null or valid tuple value
h. Delete the PROJECT tuple with Pname = ‘ProductX’
-This deletion is not acceptable because tuples in WORKS_ON refer to this tuple. Hence
referential integrity violations will result. A way to enforce this constraint is to delete tuples
that reference the tuple that is being deleted. Another option is to modify the referencing
attribute to another value such as null or valid tuple value
i. Modify the Mgr_ssn and Mgr_start_date of the DEPARTMENT tuple with Dnumber =5
to ‘123456789’ and ‘2007-10-01’, respectively.
-This modification satisfies all constraints, so it is acceptable
j. Modify the Super_ssn attribute of the EMPLOYEE tuple with Ssn = ‘999887777’ to‘943775543’.
-This modification satisfies all constraints, so it is acceptable
k. Modify the Hours attribute of the WORKS_ON tuple with Essn = ‘999887777’ andPno = 10 to ‘5.0’. lOMoARcPSD| 36625228
-This modification satisfies all constraints, so it is acceptable
- Which of the following operations are not correct? Why? Show the results of the correct operations:
a. ΠSsn, Fname, Lname, Salary(Employee)
Câu lệnh này đúng. Đúng về cú pháp của lệnh chiếu và các cột Ssn, Fname, Lname, Salary đều có
trong bảng EMPLOYEE. Kết quả là một bảng mới gồm 4 cột Ssn, Fname, Lname, Salary và tất cả
dữ liệu trong các dòng của 4 cột này.
b. σSex = F and Salary > 30000(Employee)
c. σSex = F and Salary > 30000 (ΠSsn, Fname, Lname, Salary(Employee))
Câu lệnh này đúng về cú pháp nhưng sai về logic vì phép chiếu ở trong ngoặc được thực
hiện trước và cho ra kết quả là một bảng gồm 4 cột Ssn, Fname, Lname, Salary. Sau đó
phép chọn được thực hiện trên bảng kết quả của phép chiếu với điều kiện Sex = F and
Salary > 30000. Nhưng trong bảng kết quả không có cột Sex.
d. ΠSsn, Fname, Lname, Salary (σSex = F and Salary > 30000(Employee)) Ssn Fname Lname Salary 987654321 Jennifer Wallace 43000 e. Department X Dept_Location lOMoARcPSD| 36625228 Dname Dnumber Mgr_ssn
Mgr_start_date Dnumber Dlocation Research 5 333445555 1998-05-22 1 Houston Research 5 333445555 1998-05-22 4 Stafford Research 5 333445555 1998-05-22 5 Bellaire Research 5 333445555 1998-05-22 5 Sugarland Research 5 333445555 1998-05-22 5 Houston Administration 4 987654321 1995-01-01 1 Houston Administration 4 987654321 1995-01-01 4 Stafford Administration 4 987654321 1995-01-01 5 Bellaire Administration 4 987654321 1995-01-01 5 Sugarland Administration 4 987654321 1995-01-01 5 Houston Headquarters 1 888665555 1981-06-19 1 Houston Headquarters 1 888665555 1981-06-19 4 Stafford Headquarters 1 888665555 1981-06-19 5 Bellaire Headquarters 1 888665555 1981-06-19 5 Sugarland Headquarters 1 888665555 1981-06-19 5 Houston
f. Department |X| Dept_Location Dname Dnumber Mgr_ssn Mgr_start_date Dlocation Research 5 33344555 1998-05-22 Bellaire 5 Research 5 33344555 1998-05-22 Sugarland 5 Research 5 33344555 1998-05-22 Houston 5 lOMoARcPSD| 36625228 Administration 4 98765432 1995-01-01 Stafford 1 Headquarters 1 88866555 1981-06-19 Houston 5
g. Compare the results of question e and f
Số lượng hàng và cột của câu e lớn hơn nhiều so với câu f. Câu e sử dụng
phép tính tích đề cạc, còn câu f sử dụng phép tính Natural Join . Nên câu e
có thể tồn tại các cặp trùng nhau h. Employee – Dependent
-Không trừ được bởi vì Employee và Dependent không cùng cấu trúc.
i. ΠSsn(Employee) - ΠEssn(Dependent)
-Vì có cùng cấu trúc nên trừ được Ssn 123456789 999887777 666884444 453453453 987987987
j. σSex = F and Salary > 30000(Employee) È σSex = M and Salary < 30000(Employee) Fname Minit Lname Ssn Bdate Address Sex Salary Super_snn Dno Jennifer S Wallace 987654321 1941- 291 Berry, F 43000 888665555 4 06-20 Bellaire, TX lOMoARcPSD| 36625228 Ahmad V V Jabbar 1969-03-29 980 Dallas, M 25000 987654321 4 196903- Houston, 29 TX
k. ΠSsn(σDno=5(Employee)) Ç rSsn(ΠEssn(σPno =1(Works_on))) Ssn 123456789 453453453
l. Explain the sense of the result of question j and k.
Ý nghĩa của kết quả 2 câu hỏi j và k là các phép hội hay phép giao chỉ có thể thực hiện
khi 2 quan hệ thỏa tương thích hội.
2. Given a University database as follows:
Consider the above figure. In addition to constraints relating the values of columns in one
table to columns in another table, there are also constraints that impose restrictions on
values in a column or a combination of columns within a table. One such constraint dictates
that a column or a group of columns must be unique across all rows in the table. For lOMoARcPSD| 36625228
example, in the STUDENT table, the Student_number column must be unique (to prevent
two different students from having the same Student_number).
- Identify the column or the group of columns in the other tables that must be uniqueacross all rows in the table.
- Identify the primary key, foreign key in each relational schema.
- Specify the following queries on the University database schema:
a. Retrieve the student_number and the name of all students in the university.
Π Student_number, Name(STUDENT)
b. Retrieve the student_number and the name of all students in “Computer Science”major
Π Student_number, Name(σMajor= Computer Science(STUDENT))
c. Retrieve the prerequisite course number and course name of the course which hascourse number “1111’’
Πprerequisite_number,course_number,course_name(σcourse_number=1111(COURSE|X| PREREQUISITE))
d. Retrieve the section identifier, course number and course name of courses which
areopened in semester 1, year 2019
Πsection_identifier,course_number,course_name(σsemester=1andyear=2019(COURSE| X| SECTION))
e. Retrieve the section identifier, course number and course name of courses which arenot
opened in semester 1, year 2019
Πsection_identifier,course_number,course_name(σsemester!=1 and year! =2019(COURSE|X| SECTION))
f. Retrieve the section identifier, course number and course name of courses which
areopened in year 2018 or 2019.
Πsection_identifier,course_number,course_name(σyear=2018(COURSE|X| SECTION))
Πsection_identifier,course_number,course_name(σyear=2019(COURSE|X| SECTION))
g. Retrieve the section identifier, course number and course name of courses which
areopened in year 2018 and 2019.
Πsection_identifier,course_number,course_name(σyear=2018(COURSE|X| SECTION)) lOMoARcPSD| 36625228
Πsection_identifier,course_number,course_name(σyear=2019(COURSE|X| SECTION))