Professional Documents
Culture Documents
trantngocmaiQ1
trantngocmaiQ1
Q1
I. Short answer
1. What is SQL? What are the different types of statements supported by SQL?
- SQL (Structured Query Language) is a programming language used to
manage and manipulate relational databases.
- The different types of statements supported by SQL:
+ Data Definition Language (DDL)
+ Data Manipulation Language (DML)
+ Data Control Language (DCL)
+ Transaction Control Language (TCL)
2. What difference between data and information?
- Data is raw, unprocessed facts and figures, while information is processed,
organized, and meaningful data.
- SQL constraints are used to enforce rules and restrictions on the data in a
database, ensuring data integrity and consistency. They help maintain the accuracy
and reliability of the data.
4. What is DBMS? What are the advantages of having the DBMS between the
end user’s applications and the database?
- Advantages of having the DBMS between the end user’s applications and
the database: Data integrity, security, data sharing, data independence, data
recovery, improved performance, scalability, and flexibility.
II. SQL
DOCGIA(MaDG, HoTen,NgaySinh,DiaChi,SoDT)
SACH(MaSach,TenSach,TheLoai,NhaXuatBan)
PHIEUTHUE(MaPM,MaDG,NgayThue,NgayTra,SoSachMuon)
CHITIET_PM(MaPM,MaSach)
1.1.
ALTER TABLE PHIEUTHUE
ADD CONSTRAINT CHK_THOI_GIAN_THUE
CHECK (DATEDIFF(day, NgayThue, NgayTra) <= 10);
1.2
ALTER TABLE PHIEUTHUE
ADD CONSTRAINT CHK_SO_SACH_THUE
CHECK (SoSachMuon = (SELECT COUNT(*) FROM CHITIET_PM WHERE CHITIET_PM.MaPM = PHIEUTHUE.MaPM));
2.
2.1
SELECT DOCGIA.MaDG, DOCGIA.HoTen
FROM DOCGIA
JOIN PHIEUTHUE ON DOCGIA.MaDG = PHIEUTHUE.MaDG
JOIN CHITIET_PM ON PHIEUTHUE.MaPM = CHITIET_PM.MaPM
JOIN SACH ON CHITIET_PM.MaSach = SACH.MaSach
WHERE SACH.TheLoai = 'Tin học' AND YEAR(PHIEUTHUE.NgayThue) = 2007;
2.2
SELECT TOP 1 DOCGIA.MaDG, DOCGIA.HoTen
FROM DOCGIA
JOIN PHIEUTHUE ON DOCGIA.MaDG = PHIEUTHUE.MaDG
JOIN CHITIET_PM ON PHIEUTHUE.MaPM = CHITIET_PM.MaPM
JOIN SACH ON CHITIET_PM.MaSach = SACH.MaSach
GROUP BY DOCGIA.MaDG, DOCGIA.HoTen
ORDER BY COUNT(DISTINCT SACH.TheLoai) DESC;
2.3
SELECT DISTINCT SACH.TheLoai, SACH.TenSach
FROM SACH
JOIN CHITIET_PM ON SACH.MaSach = CHITIET_PM.MaSach
GROUP BY SACH.TheLoai, SACH.TenSach
HAVING COUNT(*) = (
SELECT MAX(Total)
FROM (
SELECT COUNT(*) AS Total
FROM SACH
JOIN CHITIET_PM ON SACH.MaSach = CHITIET_PM.MaSach
GROUP BY SACH.TheLoai, SACH.TenSach
) AS Counts
WHERE Counts.TheLoai = SACH.TheLoai
);