You are on page 1of 6

Review questions

1. Describe the three-schema architecture.


Kiến trúc 3 mức giúp tách biệt các ứng dụng người dùng với CSDL vật lý.
- Mức vật lý: Sử dụng mô hình dữ liệu vật lý để mô tả cấu trúc lưu trữ vật lý của
CSDL
- Mức logic/quan niệm: Dấu đi chi tiết về cấu trúc lưu trữ vật lý. Dùng mô hình dữ
liệu logic để mô tả cái gì được lưu trữ trong CSDL và mối quan hệ giữa các dữ
liệu đó.
- Mức ngoài/ view: Mô tả một phần của CSDL cho một nhóm người dùng quan tâm
và dấu đi phần còn lại của CSDL khỏi nhóm người dùng đó.

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.

An attribute
Mỗi cột trong quan hệ được gọi là một thuộc tính
VD: từng cột trong quan hệ là một thuộc tính

The domain of an attribute


Một tập giá trị mà một thuộc tính có thể nhận.
VD: Dom(Phai) = |Phai| = {‘Nam’, ‘Nu’}
Dom(Diem) = |Diem| = [0..10]

A 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)
VD: SINHVIEN(MaSV, HoTen, NgaySinh, Diachi)

A 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ệ đó
VD:
N-tuple
Mỗi dòng được gọi là một bộ
VD: từng hàng trong quan hệ được gọi là một bộ

Degree of a relation
Là số thuộc tính của lược đồ quan hệ của nó.
VD: 4

A relationship
Biểu diễn mối kết hợp giữa các quan hệ trong CSDL (mối quan hệ dựa trên khóa ngoại).

A relation instance (state)


Tập tất cả các bộ của một quan hệ tại một thời điểm.
VD:
A 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ể.
VB: SINHVIEN(MaSV, HoTen, NgaySinh, Diachi)
MONHOC(MaMH, TenMH, SoTC)
KQTHI(MaSV, MaMH, Diem)

A relational database state


Một tập các quan hệ có liên quan với nhau về một lĩnh vực cụ thể.
VD: Một phần CSDL quan hệ trong một ứng dụng quản lý SV của một trường

Integrity constraints.
Tập các quy tắc mà mọi dữ liệu trong CSDL phải tuân theo nhằm đảm bảo tính toàn vẹn
của cơ sở dữ liệu.

3. Why are tuples in a relation not ordered?


Vì nó không ảnh hưởng gì tới CSDL cũng như không ảnh hưởng tới thao tác chèn xóa,
thêm và tốc độ truy xuất dữ liệu.

4. Why are duplicate tuples not allowed in a relation?


Vì nó tạo ra sự dư thừa của CSDL và ảnh hưởng đến các thao tác như chèn, xóa, thêm
làm giảm tốc độ truy xuất.

5. What is the difference between a key and a superkey?


Superkey là bất kỳ tập con thuộc tính nào xác định duy nhất các bộ giá trị của một quan
hệ. Tập hợp con này có thể xóa một số thuộc tính khỏi nó và nó vẫn nhận dạng duy
nhất. Nếu tất cả các thuộc tính thừa bị loại bỏ, bạn sẽ nhận được một tập hợp con được
gọi là khóa chính.
Key là tập con tối thiểu của các thuộc tính xác định duy nhất các bộ giá trị của một mối
quan hệ, nghĩa là bạn không thể xóa thêm các thuộc tính khỏi tập hợp con này mà không
làm mất thuộc tính nhận dạng duy nhất.

6. Discuss the entity integrity and referential integrity constraints. Why is each considered
important?
Tính toàn vẹn của thực thể nói rằng không có khóa chính nào có thể có giá trị NULL.
Điều này là do khóa chính được sử dụng để xác định một bộ mã và nếu hai bộ mã có
NULL cho khóa chính của chúng, chúng sẽ không thể phân biệt và không thể xác định
được.
Ràng buộc toàn vẹn tham chiếu nói rằng một bộ trong một quan hệ tham chiếu đến một
quan hệ khác phải tham chiếu đến một bộ tồn tại trong quan hệ đó.

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.
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 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 unique across 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.
b. Retrieve the student_number and the name of all students in “Computer Science”
major
c. Retrieve the prerequisite course number and course name of the course which has
course number “1111’’
d. Retrieve the section identifier, course number and course name of courses which are
opened in semester 1, year 2019
e. Retrieve the section identifier, course number and course name of courses which are
not opened in semester 1, year 2019
f. Retrieve the section identifier, course number and course name of courses which are
opened in year 2018 or 2019.
g. Retrieve the section identifier, course number and course name of courses which are
opened in year 2018 and 2019.

You might also like