Tải bản đầy đủ (.docx) (17 trang)

Kết quả database

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (203.67 KB, 17 trang )

1.

Bảng A
ColA
A
B
D
F
G
Bảng B

ColB
2
5
7
7
17

ColA
A
H
K
J
B
KQ1:

ColB
2
5
7
9


9

ColA
A
KQ2:

ColB
2

ColA
A
B
B
D
F
G
H
J
K

ColA
AB
CD
DK
HZ

Col1
A
Z
H

G

ColA
AB
CK
DF
HI
Bảng B

ColB
2
5
9
7

Col3
2
17
35
69

Sử dụng phép toán như sau:
Q1= A B ; Q2= A\B
[Q1 Q2].{A}
Có KQ như sau:
a. KQ= {AB}
b. KQ= {AB,AB}
c. KQ=

ColB

2
5
9
7
9
17
5
9
7

Phép kết nào cho được 2 KQ trên:
a. KQ1 dùng “interset all”, KQ2 dùng “union
all”
b. KQ1 dùng “interset”, KQ2 dùng “union” +
order by để sắp xếp KQ
c. KQ1 dùng “interset all”, KQ2 dùng
“union”
d. KQ1 dùng “interset”, KQ2 dùng “union”
2.

3. Cho bảng A

d. KQ= null
4.
5. Bảng Z
Col1
A
Z
H
K

Bảng K
Câu truy vấn như sau:
SELECT

Z.Col1,Z.Col2

FROM
(SELECT

Z RIGHT INNER JOIN
*

FROM Z inner join K on
__________
WHERE Z.Col1 not in (H,K,Q) )


KQ như sau:

W

b. KQ=

d. KQ=
Col1
A
Z
H
K


Col1
A
Z
H
G

c. KQ=

c. S

d.name
department d

W

(S

count(e.empid)

F
Col1
A
Z
A
Z

employee e

W
d.empid) <2

d. S

Deptid
A1
A1
A3

Deptid
Deptname
A1
IT
A2
HR
A3
Sales
Lập danh sách phịng ban có số
nhân viên <2:
d.Name
F

department d

W

(S

Count(E.empid)

F


Employee e) <2

d.name
F

e.empid =

d.name
F

department d

department d

W

Empid
Empname
01
John
02
Lee
03
Cathy
Bảng Department

b. S

e.deptid =


F

(S

count(e.empid)

F

employee

G

7. Bảng Employee

a. S

employee e

W
d.deptid) <2

e. KQ=
Col1
A
Z

Count(e.empid)

F


a.

(S

e.deptid) <2

8.
9. Bảng
hanghoa
MaHang
H01
H02
H03
H04

Bảng
CTHD
MaHD
HD1
HD2
HD2
HD2
HD3
HD3

MaHang
H01
H01
H02
H03

H01
H04


Lập danh sách mặt hàng nào được mua bởi tất cả hóa đơn?
a. S

h.tenhang
F

ct.mahang, count(ct.mahd) as T

F

CTHD ct

G
W

(S

ct.mahang ) AS Q inner join hanghoa AS h

Q.T= (S

count(Z.maHD)
F

b. S


CTHD Z)

h.tenhang
F

ct.mahang, count(ct.mahd) as T

F

CTHD CT

W
W

(S

ct.mahang) AS Q inner join hanghoa h

Q.T= (S

Count(distinct (Z.maHD))
F

c. S

CTHD Z)

h.tenhang
F


ct.mahang, count(ct.mahd) As T)

F

CTHD CT

G
W

(S

ct.mahang) AS Q inner join hanghoa h

Q.T=(S

Count(*)
F

d. S

CTHD Z)

hh.tenhang
F

ct.mahang, count(ct.mahd) As T)

F

CTHD CT


G
W

(S

ct.mahang) AS Q inner join hanghoa h

Q.T=(S

distinct count Z.maHD
F

CTHD Z)


10. Model nào là công cụ hữu hiệu nhất trong thiết kế CSDL quan hệ
a. Relational data model
b. Hierarchical data model
c. Entity – Relationship model
d. Network model
11. House Relation

Điền giá trị cho A: attribute B tuple degree: 5 cardinality: 3
12. Thống kê Relation: lưu trữ thống kê theo điểm của Tốn, Lý, Hóa đã được rời rạc hóa các giá trị
(giá trị 1 là điểm <5, 2 là >=5 )
Toan
Ly
Hoa
1

2
1
2
1
1
1
1
1
Cả 3 cột Toan, Ly, Hoa có chung gì? Dimesion bao nhiêu?
a. Chung dimension là 1; 2
b. Chung instance, dimesion là 1; 2
c. Chung schema, dimesion là 2
d. Chung domain, dimesion là 2
13. 1 Relation, quy tắc nào không áp dụng
a. Khơng có 2 địng trùng nhau trong 1 quan hệ
b. Phải có header và body
c. Phải có ít nhất 1 attribute
d. Các attributes được sắp xếp theo Alphabet
14. Nhận định nào khơng đúng:
a. 1 Relation phải có tối thiểu 1 candidate key
b. Candidate key chứa số thuộc tính nhỏ nhất
c. Có duy nhất 1 primary key

MaSV
01
02
03


d. 1 realtion phải có tối thiểu 1 alternate key

15. 1 Khóa khơng ý nghĩa thực tế, có kiểu số và tăng dần, gọi là:
a.
b. Surrogate key

d. Priamary key

c. Artificial key

e. Alternate key

f.
16. Chìa khóa để kết hợp nhiều relation lại với nhau là:
a. Primarry key, đặt khóa chính của bảng này vào bảng khác
b. Foreign key, 1 thuộc tính của bảng này trùng khớp với khóa chính của bảng khác.
c. Candidate key, 1 candidate key của bảng này trùng khớp với khóa chính của bảng khác
d. Tất cả đều sai.
17. Ràng buộc khơng chấp nhận giá trị tại khóa chính null
a. Entity integrity constraint
b. Referential integrity constraint
c. Unique constraint
d. Null constraint
18. Delete nullifiles là:
a. Gán giá trị null tại khóa chính của bảng cha, sau đó xóa dịng có khóa chính là null vừa mới gán.
b. Gán giá trị null tại khóa ngoại của bảng con mà có giá trị trùng với khóa chính của bảng cha
tại dịng cần được xóa, sau đó xóa dịng tại bảng cha.
c. Chỉ xóa 1 dịng ở bảng cha khi khóa ngoại ở bảng con mà tham chiếu đến khóa chính là null.
d. Có thể thực hiện xóa dl khi cột làm foreign key ở bảng con là not null.
19. Xóa dữ liệu tại bảng cha và bảng con có foreign key bằng giá trị primary key của bảng cha được
xóa khi chọn:
a.

b. Delete

c. Cascade


d. Restrict

20.

e. Nullifiles
21. Có 1 ràng buộc quy định giá trị tại cột mã sinh viên là: XXX999XXXX , ràng buộc này tên gọi là gì và
khi nhập giá trị là 999K27ABCD có báo lỗi khơng?
a. Check constraint, khơng báo lỗi
b. Check constraint, báo lỗi vì ‘K’ ở vị trí 4 phải là số
c. Format constraint, báo lỗi vì ‘9’ ở vị trí 1 phải là chuỗi alphabet
d. Format constraint, báo lỗi vì ‘K’ ở vị trí 4 phải là số
22. Primary key chứa ràng buộc sau là mặc định
(câu trả lơi đúng nhất)
a. Null constraint

d. Entity integrity constraint

b. Unique constraint

23.

c. Check constraint
24. Để đảm bảo giá trị nhập vào tại cột số lượng phải >0 thì khai báo như sau:
a. Create table chitiet( soluong int check soluong > 0,…)
b. Dùng trigger KT khi insert thì giá trị tại cột soluong >0 không?

c. Create table chitiet( soluong int,…,constraint check soluong >0)
d. Create table chitiet(soluong int,…, add constraint check soluong > 0)
25. Phép tốn quan hệ nào cho KQ có cùng degree của R1 và R2
a.
b. Union

e. Cartesion product

c. Intersection

26.

d. Difference
27. 2 phép toán QH union và intersection đều bắt buộc:
a. R1 và R2 cùng degree
b. Các thuộc tính giữa R1 và R2 cùng domain


c. R1 và R2 cùng instance
d. R1 và R2 cùng tuples
28. Lấy tất cả tuples thuộc R1 nhưng không thuộc R2
a.
b. R1 intersect R2

e. R1 times R2

c. R1 difference R2

29.


d. R1 minus R2
30. Nhận định nào đúng về difference:
a. R1 và R2 cùng degree
b. Có thể giao hốn và kết hợp
c. Các thuộc tính giữa R1 và R2 cùng domain
d. KQ có số degree tăng
31. Nhận định nào khơng đúng về cast esian product:
a. Số tuples của KQ=số tuples R1 + số tuples R2
b. R1 và R2 có thể khác nhau về degree
c. Số degree của KQ bằng số degree của R1 hoặc R2
d. Thuộc tính của R1 và R2 khơng cùng domain
32. Kí hiệu (Sex=M and Age >19) (R) là :
a. Projection R theo điều kiện Sex = M và Age >19
b. Selection R theo điều kiện Sex = M và Age > 19
c. KQ có degree bằng số degree của R
d. KQ có cardinality > số cardinality của R
33. Cho Relation student
Student ID
01
02
03

LastName
John
Marry
Jim

FirstName
A
B

B


Xuất KQ có duy nhất cột FirstName
a.
b. (FirstName) (Student) KQ là

FirstName
A
B
e. (FirstName) (Student) KQ là:

FirstName
A
B
c. (FirstName) (Student) KQ là
FirstName
A
B
B
d. (FirstName) (Student) KQ là:

34.

FirstName
A
B
B



26. Given the following two tables:
NAMES
----------------------------NAME
NUMBER
---------------Wayne Gretzky
99
Jaromir Jagr
68
Bobby Orr
4
Bobby Hull
23
Mario Lemieux
66
POINTS
----------------------------NAME
POINTS
--------------Wayne Gretzky
244
Bobby Orr
129
Brett Hull
121
Mario Lemieux
189
Joe Sakic
94

How many rows would be returned using the following statement?
SELECT name FROM names, points



A. 0



B. 5



C. 10



D. 25

27. Given the following two tables:
TAB1
---------------------COL_1
COL_2
--------A
10
B
12
C
14
TAB2
---------------------COL_A
COL_B
--------A

21
C
23
D
25

Assuming the following results are desired:
COL_1
A
B
C
-

COL_2
10
12
14
-

COL_A
A
C
D

Which of the following joins will produce the desired results?

COL_B
21
23
25





A. SELECT * FROM tab1 INNER JOIN tab2 ON col_1 = col_a



B. SELECT * FROM tab1 LEFT OUTER JOIN tab2 ON col_1 = col_a



C. SELECT * FROM tab1 RIGHT OUTER JOIN tab2 ON col_1 = col_a



D. SELECT * FROM tab1 FULL OUTER JOIN tab2 ON col_1 = col_a

28.
Given the following table:
TAB1
COL1
----A
B
C
A
D
C

COL2

----10
20
30
10
40
30

Assuming the following results are desired:
TAB1
COL1
----A
B
C
D

COL2
----10
20
30
40

Which of the following statements will produce the desired results?


A. SELECT UNIQUE * FROM tab1



B. SELECT DISTINCT * FROM tab1




C. SELECT UNIQUE(*) FROM tab1



D. SELECT DISTINCT(*) FROM tab1

29.
Given the following two tables:
EMPLOYEE
ID NAME

DEPTID

-- ---------------- --01 Mick Jagger

10

02 Keith Richards 20
03 Ronnie Wood

20


04 Charlie Watts 20
05 Bill Wyman

30


06 Brian Jones DEPARTMENT
ID DEPTNAME
-- -----------------10 Executive Staff
20 Sales
30 Marketing
40 Engineering
50 Human Resources
Which two of the following queries will display the employee name and department name for all
employees that are in Sales?
• A.
SELECT e.name, d.deptname
FROM employee e, department d
WHERE e.deptid = d.id AND d.id = '20'

• B.
SELECT e.name, d.deptname
FROM employee e FULL OUTER JOIN department d
ON e.deptid = d.id
WHERE d.id = '20'

• C.
SELECT e.name, d.deptname
FROM employee e RIGHT OUTER JOIN department d
ON e.deptid = d.id
WHERE d.id = '20'

• D.
SELECT e.name, d.deptname
FROM employee e LEFT OUTER JOIN department d
ON e.deptid = d.id

WHERE d.id = '20'

• E.
SELECT e.name, d.deptname
FROM employee e INNER JOIN department d
ON e.deptid = d.id


30.
Given the following two tables:
NAMES
NAME

NUMBER

----------

-------

Wayne Gretzky

99

Jaromir Jagr

68

Bobby Orr

4


Bobby Hull

23

Brett Hull

16

Mario Lemieux

66

Mark Messier

11

POINTS
NAME

POINTS

----------

------

Wayne Gretzky

244


Jaromir Jagr

168

Bobby Orr

129

Brett Hull

121

Mario Lemieux
Joe Sakic

189
94

Which of the following statements will display the player name, number, and points for all players
that have scored points?



B. SELECT p.name, n.number, p.points FROM names n LEFT OUTER JOIN points p ON
n.name = p.name



C. SELECT p.name, n.number, p.points FROM names n RIGHT OUTER JOIN
points p ON n.name = p.name




31.

A. SELECT p.name, n.number, p.points FROM names n INNER JOIN points p ON n.name
= p.name

D. SELECT p.name, n.number, p.points FROM names n FULL OUTER JOIN points p ON
n.name = p.name


Given the following tables:
YEAR_2006
EMPID NAME
----- --------------1

Jagger, Mick

2

Richards, Keith

3

Wood, Ronnie

4

Watts, Charlie


5

Jones, Darryl

6

Leavell, Chuck

YEAR_1962
EMPID NAME
----- --------------1

Jagger, Mick

2

Richards, Keith

3

Jones, Brian

4

Wyman, Bill

5

Watts, Charlie


6

Stewart, Ian

If the following SQL statement is executed, how many rows will be returned?
SELECT name FROM year_2007
UNION ALL
SELECT name FROM year_1962


A. 6



B. 9



C. 10



D. 12

32.
Given the following table definition:
SALES
--------------------------------------



INVOICE_NO

CHAR(20) NOT NULL

SALES_DATE

DATE

SALES_PERSON
REGION

VARCHAR(25)

CHAR(20)

SALES_AMT

DECIMAL(9,2)

Which of the following queries will return SALES information, sorted by SALES_PERSON, from
A to Z, and SALES_DATE, from most recent to earliest?


A. SELECT invoice_no, sales_person, sales_date, sales_amt FROM sales SORT BY
sales_person, sales_date DESC



B. SELECT invoice_no, sales_person, sales_date, sales_amt FROM sales SORT BY

sales_person DESC, sales_date



C. SELECT invoice_no, sales_person, sales_date, sales_amt FROM sales ORDER BY
sales_person, sales_date DESC



D. SELECT invoice_no, sales_person, sales_date, sales_amt FROM sales ORDER BY
sales_person DESC, sales_date

33.
Given the following table definitions:
DEPARTMENT
-------------------------DEPTNO

CHAR(3)

DEPTNAME

CHAR(30)

MGRNO

INTEGER

ADMRDEPT

CHAR(3)


EMPLOYEE
-------------------------EMPNO

INTEGER

FIRSTNAME CHAR(30)
MIDINIT

CHAR

LASTNAME

CHAR(30)

WORKDEPT

CHAR(3)

Which of the following statements will list every employee number and last name, along with the
employee number and last name of their manager, including employees that have not been
assigned to a manager?


A. SELECT e.empno, e.lastname, m.empno, m.lastname FROM employee e LEFT INNER
JOIN department INNER JOIN employee m ON mgrno=m.empno ON e.workdept=deptno





B. SELECT e.empno, e.lastname, m.empno, m.lastname FROM employee e LEFT
OUTER JOIN department INNER JOIN employee m ON mgrno=m.empno ON
e.workdept=deptno



C. SELECT e.empno, e.lastname, m.empno, m.lastname FROM employee e RIGHT
OUTER JOIN department INNER JOIN employee m ON mgrno=m.empno ON
e.workdept=deptno



D. SELECT e.empno, e.lastname, m.empno, m.lastname FROM employee e RIGHT
INNER JOIN department INNER JOIN employee m ON mgrno=m.empno ON
e.workdept=deptno

34.
Given the following table:
EMPLOYEE
EMPID

NAME

INSTRUMENT

---

--------------- -----

1


Jagger, Mick 01

2

Richards, Keith 02

3

Wood, Ronnie 02

4

Watts, Charlie 03

5

Jones, Darryl 04

6

Leavell, Chuck 05

If the following query is executed:
SELECT name,
CASE WHEN instrument = '01' THEN 'HARMONICA'
WHEN instrument = '02' THEN 'GUITAR'
WHEN instrument = '03' THEN 'DRUMS'
ELSE 'UNKNOWN'
END AS instrument

FROM employee
What will be the results?
• A.
NAME
--------------Jagger, Mick
Richards, Keith
Wood, Ronnie
Watts, Charlie
Jones, Darryl
Leavell, Chuck

INSTRUMENT
-------HARMONICA
GUITAR
GUITAR
DRUMS
ERROR
ERROR


• B.
NAME
-----------------Jagger, Mick
Richards, Keith
Wood, Ronnie
Watts, Charlie
Jones, Darryl
Leavell, Chuck

INSTRUMENT

-------HARMONICA
GUITAR
GUITAR
DRUMS
04
05

• C.
NAME
-----------------Jagger, Mick
Richards, Keith
Wood, Ronnie
Watts, Charlie
Jones, Darryl
Leavell, Chuck

INSTRUMENT
-------HARMONICA
GUITAR
GUITAR
DRUMS
UNKNOWN
UNKNOWN

• D.
NAME
-----------------Jagger, Mick
Richards, Keith
Wood, Ronnie
Watts, Charlie

Jones, Darryl
Leavell, Chuck

INSTRUMENT
-------HARMONICA
GUITAR
GUITAR
DRUMS
-



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×