Sie sind auf Seite 1von 38

1.

Table Name: animals


Row_i
d
1

family

3
4
5

Mamm
al
mamm
al
fish
bird
bird

fish

anim
al
Dog

Color

zebra

Black, white

shark
gull
pelic
an
trout

gray
White
white

brown

Gray

SELECT animal
From animals
ORDER BY animal DESC
What is the value of animal in the first row returned?
Options:
A. dog
B. shark
C. trout
D. pelican
E. zebra
Answer: E
2.

SELECT emp_num, years, SUM(salary)


FROM sales
UNION ALL
SELECT emp_id, SUM(takehomepay)
FROM marketing
Which of the following problems will not result in an error?

Options:
A.
B.
C.
D.

emp_num and emp_id do not match names


Aggregate functions need GROUP By clauses
SUM(salary) and SUM(takehomepay) do not match names
UNION ALL queries need the same number of elements in the SELECT
clauses
E. UNION ALL queries will result in duplicates
Answer: D

3.

--- EMP--NAME
SALARY
-----------------Chevalier
30000
Smith
28000
Wong
35000
Hadiz
32000
Hu
24000
Travino
28000
Boyer
20000

DEPT
-------10
20
30
10
20
10
40

SELECT name
FROM emp
WHERE dept=10
Referring to the above scenario, which of the following index definitions
would avoid the direct retrieval of rows from the EMP table when executing
the query?
Options:
A.
B.
C.
D.
E.

CREATE
CREATE
CREATE
CREATE
CREATE

INDEX
INDEX
INDEX
INDEX
INDEX

emp_perf_idx
emp_perf_idx
emp_perf_idx
emp_perf_idx
emp_perf_idx

ON
ON
ON
ON
ON

emp(dept)
emp(name, salary)
emp(name)
emp(dept, name)
emp(dept, salary)

Answer: A
4.

Table Name: combos


row_i a
b
c
d
1
cat
NUL dog
L
2
lion
dog NUL
L
3
NULL bird ferre
t
4
lynx
ant
bat
5
fly
bee beeti
e
6
fish
fish
crick
et
SELECT MAX(a), MIN(b), MAX(c) FROM combos
What is returned when the sample code above is expected?

Options:

A.
B.
C.
D.
E.

lynx
lynx
NULL
lynx
lynx

NULL
fish
NULL
ant
bee

ferret
ferret
NULL
ferret
lion

Answer: D
5. SELECT COUNT(b.title)
FROM books b
Where b.genre = Horror
AND b.title IS NULL
Why does the above query fail to find an accurate count from the books table
in which the title is missing for a specific genre?
Options:
A. This query never returns a value higher than 1 because the COUNT (b.title)
function couns the unique values
B. The proper syntax for the last line of the query is HAVING b.title IS NULL.
C. The proper syntax for the last line of the query is HAVING b.title AS NULL.
D. The conditions in the WHERE clause need to be reversed. Otherwise, all Horror
titles (NULL or non-NULL) will be included in the count.
E. The COUNT(b.title) function does not count NULL values in that field
Answer: E
1. Expenses
dept type dollar
------ ------- ------A
P
100
A
D
0
A
S
50
B
P
NULL
B
P
10
B
D
100
B
S
500
C
D
400
C
S
100
Returns
type ratio
------ ------P
2.00
S
3.00
D
2.00
N
5.00
SELECT e.type, SUM(r.ratio*e.dollar)
FROM expenses e, returns r

WHERE e.type=r.type
GROUP BY e.type
HAVING SUM(r.ratio*e.dollar) < 300
Referring to the tables above, which rows does the query select?
Options:
A. P 100.00
D 220.00
B. D 10000.00
S 1950.00
C. D 220.00
D. D 1000.00
S 1950.00
E. P

220.00

Answer: E
2. SELECT id, last_name, first_name, salary
FROM employees e, payroll p
WHERE e.id = p.id
AND salary > ALL
(SELECT AVG(pa.salary) FROM payroll pa
GROUP BY pa.type)
ORDER BY 2,3
What is the problem with the query above?
Options:
A. You cannot refer to a table in the subquery that is also a joined table in the
main query.
B. The GROUP BY statement in the subquery is invalid because the column to
which it refers is not in the SELECT list of the subquery.
C. The id column in the SELECT list is ambiguous and needs to be qualified
with a table name or alias.
D. The ORDER BY clause must refer to column names rather than their positions
in the SELECT list.
E. The > operator cannot be used in conjunction with the ALL keyword to
introduce a subquery.
Answer: C
3.

Table Name: Customers


row gend
department
_id
er
1
femal housewares

Purch
ases
27.75

2
3

4
5
6
7

e
male
femal
e
femal
e
male
femal
e
Male

garden
home
improveme
nt
kitchen/bat
hroom
furniture

42.20
97.50

28.60

garden

225.7
5
34.40

hardware

16.50

SELECT department, COUNT(*) FROM customers


WHERE gender LIKE %male
AND purchases > 30.00
GROUP BY department ORDER BY 1
How many rows does the above query return?
Options:
A. Zero rows
B. Two rows
C. Three rows
D. Four rows
E. Six rows
Answer: C
4. Bus
vid
---1
2
3
4
5
car
vid
---10
20
30
40

seats age
------- ----10
10
20
4
10
6
40
6
10
NULL
seats
-----4
10
10
8

age
-----6
4
4
10

1
DELETE FROM bus b, car c WHERE c.seats >=b.seats AND c.age <= b.age
2

DELETE FROM car c WHERE EXISTS (SELECT b.* FROM bus b WHERE b.seats
>= c.seats AND b.age <= c.age)
3
DELETE FROM bus b WHERE EXISTS (SELECT c.* FROM car c WHERE c.seats
>= b.seats and c.age <= b.age)
4
DELETE FROM bus b WHERE vid IN (SELECT DISTINCT b1.vid FROM bus b1,
car c1 WHERE c1.seats >= b1.seats AND c1.age <= b1.age)
Referring to the tables above, which two statements delete the same rows?
Options:
A. 2,3
B. 1,2
C. 1,4
D. 3,4
E. 1,3
Answer: D
5.

--- EMP--NAME
--------Smith
Boyer
Sawi

SALARY
----------32000
20000
38000

DEPT
--------20
40
60

UPDATE emp
SET salary = salary * 1.5, dept = salary / 100
WHERE salary > (SELECT AVG(salary) from emp)
After the update above, what do the rows of the EMP table contain?
Options:
A. Smith
Boyer
Sawi

32000
20000
38000

48
40
57

B. Smith
Boyer
Sawi

48000
20000
57000

48
40
57

C. Smith
Boyer
Sawi

32000
20000
38000

20
40
60

D. Smith
Boyer
Sawi

48000 32
20000 40
57000 38

E. Smith
Boyer
Sawi

48000
20000
57000

32
20
38

Answer: D

6. T1
cno
-----1
1
2
3
3
3
4

cnt
-----1
2
1
4
5
9
99

DELETE FROM t1 WHERE EXISTS


(SELECT t.* FROM t1 t
WHERE t1.cno = t.cno
AND t1.nct > t.cnt)
Referring to the scenario above, how many rows remain in table T1?
Options:
A. Two
B. Three
C. Four
D. Five
E. Six
Answer: E
7. UPDATE emp SET dept =
(SELECT MAX (dept) from
(SELECT dept FROM emp
GROUP BY dept
HAVING avg(salary) IN
(SELECT max(avg(salary))
)
)
WHERE dept IN
(SELECT dept FROM emp
GROUP BY dept
HAVING avg(salary) IN

(SELECT min (avg(salary))


FROM emp
GROUP BY dept)
)
In the above scenario, what is the effect of the update being made to the
EMP table?
Options:
A. All employees in the departments with the lowest average salary are being
placed in one of the departments with the highest average salary.
B. All employees in the department with the lowest average salary are being
placed in one of the departments with the highest maximum salary.
C. All employees are being placed in one of the departments with the highest
average salary
D. All employees in the departments with the highest average salary are being
placed in one of the departments with the lowest average salary.
E. All employees are being placed in one of the departments with the highest
maximum salary.
Answer: B
8.

Table Name: animals


row_i
d
1

family

3
4

mamm
al
mamm
al
fish
bird

bird

fish

anima
l
dog

color

zebra

black &
white
gray
red

shark
cardin
al
pelica
n
trout

brown

white
gray

SELECT family, color


FROM animals
ORDER BY family, color DESC
What are the contents of the first row returned by the above query?
Options:
A. bird, white
B. fish, gray
C. mammal, black & white
D. bird, red
E. mammal, brown

Answer: A
9.

----EMP---NAME
SALARY
DEPT
James
35000
10
Jones
22000
20
Christopher 21000
30
John
34000
10
Andrew
48000
20
Ricky
54000
10
Mathews
32000
40
Adam
20000
50
Jennifer
24000
60
SELECT name, salary, dept
FROM emp e
WHERE NOT EXISTS (SELECT 1
FROM emp
WHERE dept = e.dept
GROUP BY dept
HAVING AVG(salary) >
(SELECT AVG(salary)
FROM emp)
)
Referring to the above scenario which employees are retrieved from the EMP
table?

Options:
A. All employees who work for a department that has an average salary lower
than or equal to the average salary of departments with more than one
employee.
B. All employees who work for a department that has an average salary lower
than or equal to the average salary of all employees.
C. All employees who work for a department that has an average salary higher
than the average salary of all employees.
D. All employees who work for a department that has an average salary higher
than the average salary of departments with one employee.
E. All employees who work for a department that has an average salary higher
than the average salary of departments with more than one employee.
Answer: B
10.SELECT *
FROM customer
Which one of the following do you add to the query shown above in order to
find the customer whose last name sounds something like SHOOLS?
Options:

A.
B.
C.
D.

WHERE name like SH%


WHERE name like SOUNDEX(SHOOLS)
WHERE name = SOUNDEX(SHOOLS)
WHERE name like %SH%
OR name like CH%
E. WHERE SOUNDEX(name) = SOUNDEX(SHOOLS)
Answer: E

11.emp
empno
--------10

dept
------AAA

job
------analyst

20

AAA

salesrep

30

BAA

dba

40

BAA

webmaste
r
webmaste
r
NULL

50

ZZZ

60

CCC

salary
--------80000.0
0
60000.0
0
50000.0
0
40000.0
0
40000.0
0
30000.0
0

comm
---------.00
10000.
00
1000.0
0
50000.
00
60000.
00
60000.
00

CREATE TABLE emp2


(
empno INT,
dept CHAR(10),
job CHAR(10),
salary DECIMAL (8, 2),
comm DECIMAL (8, 2)

INSERT INTO emp2


SELECT * FROM emp
WHERE job NOT LIKE w%
Referring to the scenario above, what data does table emp2 contain after the SQL
statements are run?
Options:
A. 10
20
30
10
B. 10
20
30

AAA
AAA
BAA
ZZZ

analyst
salesrep
dba
webmaster

80000.00
60000.00
50000.00
40000.00

.00
10000.00
1000.00
50000.00

AAA
AAA
BAA

analyst
salesrep
dba

80000.00
60000.00
50000.00

.00
10000.00
1000.00

C. 10
20
30
30

AAA
AAA
BAA
BAA

analyst
80000.00
salesrep
60000.00
dba
50000.00
webmaster 40000.00

.00
10000.00
1000.00
50000.00

D. 10
20
30
60

AAA
AAA
BAA
CCC

analyst
salesrep
dba
NULL

80000.00
60000.00
50000.00
30000.00

.00
10000.00
1000.00
50000.00

E. 20
30
60

AAA
BAA
CCC

salesrep
dba
Null

60000.00
50000.00
30000.00

10000.00
1000.00
50000.00

Answer: B
12.HR
emp_id
----------1
3
4
5
6
8
9
10

dept
-------A
A
A
B
B
C
D
E

sex
-----M
F
F
M
F
F
M
M

sal
-----80000.00
20000.00
25000.00
50000.00
60000.00
90000.00
70000.00
90000.00

SELECT DISTINCT dept FROM hr hr1 WHERE sex=M


AND sex = ANY
(SELECT sex FROM hr hr2 WHERE hr1.dept=hr2.dept
AND sal <
(SELECT avg(sal) FROM hr hr3
WHERE hr3.dept=hr2.dept))
ORDER BY dept
Referring to the table above, which department does the query return?
Options:
A. A
B. B
C. C
D. D
E. E
Answer: B

13. CUST
cust
10
20
30
40
50

name
Tim
Sam
David
Alex
Greg

Owes_
20.00
30.00
NULL
.00
40.00

CREATE VIEW v_customer AS


SELECT * FROM customer
WHERE owes_us > (SELECT AVG(owes_us) FROM customer)
UPDATE v_customer SET owes_us =
CASE WHEN owes_us > 5
THEN owes_us 5
ELSE 0
END
How does the above table look after the view update?
Options:
A.

B.

C.

D.

E.

Answer: C

10
20
40
50
10
20
30
40
50
10
20
30
40
50
10
20
30
40
50
10
20
40
50

Tim
Sam
Alex
Greg
Tim
Sam
David
Alex
Greg
Tim
Sam
David
Alex
Greg
Tim
Sam
David
Alex
Greg
Tim
Sam
Alex
Greg

15.00
25.00
.00
35.00
15.00
25.00
NULL
.00
35.00
20.00
25.00
NULL
.00
35.00
20.00
30.00
NULL
.00
40.00
20.00
25.00
.00
35.00

14. You are connected to a SQL database and are issuing Data Manipulation
Language(DML) Statements.
In the above scenario, how do you indicate that you want to be able to undo the
data manipulations you have done so far but that you want to start a new series of
DML statements that you want to be able to undo separately from the first set?
Options:
A. Instruct the database to save future changes in a different log file
B. Instruct the database to create a savepoint
C. Instruct the database to begin a new transaction
D. Open a separate session to the database server
E. Instruct the database to checkpoint your work so far
Answer: B
15.CREATE TABLE test(f1 CHAR(1), f2 CHAR(1))
CREATE INDEX ind ON test(f1, f2)
Referring to the above, which of the following set of SQL statements uses index
ind to avoid full table scans of the table tests?
Options:
A. SELECT f1, f2 FROM test WHERE f1 = 1
UNION
SELECT f1, f2 FROM test WHERE f2 = 1
B. CREATE VIEW v AS
SELECT f1, f2 FROM test WHERE f1 =1
UNION
SELECT f1, f2 FROM test WHERE f2 =1
CREATE INDEX v_ind ON v(f1,f2)
SELECT f1, f2 FROM v
C. CREATE VIEW v1 AS
SELECT f1, f2 FROM test WHERE f1 =1
UNION
SELECT f1, f2 FROM test WHERE f2 = 1
SELECT f1, f2 FROM v1
CREATE TABLE tmp(f1 char(1), f2 char(1)
D. INSERT INTO tmp
SELECT f1, f2 FROM test WHERE f1 = 1 AND f2 = 1
SELECT * FROM tmp

E. SELECT f1,f2 FROM test WHERE f1 = 1 OR f2 = 1


Answer: A
16. --- EMP--NAME
Vicky
Haider
Tom

SALARY
36000
30000
33000

DEPT
10
10
10

Given the above table, which SELECT statement produces the output shown?
Options:
A. SELECT CONCAT(Lastname:,name) AS Employee,
CONCAT(Salary / 1000, Thousands)
AS Yearly Pay in $K
FROM emp
B. SELECT CONCAT(Lastname:,name) AS Employee,
CONCAT(Salary / 1000, Thousands)
AS Yearly Pay in $K
FROM emp
C. SELECT CONCAT(Lastname:,name) AS Employee,
Salary / 1000,Thousands)
AS Pay In $K
FROM emp
D. SELECT CONCAT(Lastname:,name) AS Employee,
Salary / 1000 AS Yearly, Thousands
AS Pay in $K
FROM emp
E. SELECT CONCAT(Lastname:,name) AS Employee,
Salary / 1000 AS Yearly, Thousands
AS Pay in $K
FROM emp
Answer: E
17.CREATE TABLE test1 (ipk INT PRIMARY KEY)
INSERT INTO test1 VALUES (NULL)
INSERT INTO test1 VALUES (0)
CREATE
INSERT
INSERT
INSERT
INSERT

TABLE test5 (c INT UNIQUE REFERENCES test1 (ipk))


INTO test5 VALUES (NULL)
INTO test5 VALUES (1)
INTO test5 VALUES (0)
INTO test5 VALUES (0)

INSERT INTO test5 VALUES (1)


SELECT * FROM test5
What is the result if you run all of the above statements individually and in the order
shown?
Options:
A. 0
B. NULL
1
0
0
1
C. NULL
1
0
D. NULL
0
0
E. NULL
0
Answer: E
18. Part
pno
name
1
Axle
2
Wheel
3
Handle
4
Door

price
200.00
100.00
10.00
300.00

Suppl
sno
1
2
3
4

Name
Detroit1
Detroit2
Orlando
Flin
Part_Suppl

sno
1
1
2
3
3

pno
1
2
3
4
4

cnt
10
20
10
30
10

SELECT s.name AS supplier, p.name AS part, cnt

FROM (SELECT sno, pno, SUM(cnt) AS cnt


FROM part_suppl
GROUP BY sno, pno) AS ps, suppl s, part p
WHERE p.pno = ps.pno and s.sno = ps.sno
Referring to the tables above, what is the result set of the query?
Options:
A.

B.

C.

D.

E.

Detroit 1
Detroit 2
Detroit 2
Orlando
Detroit 1
Detroit 1
Flint
Orlando
Detroit 1
Detroit 1
Detroit 2
Orlando
Windsor
Detroit 1
Detroit 2
Orlando
Detroit 1
Detroit 1
Detroit 2
Orlando

Axle
Wheel
Handle
Door
Axle
Wheel
Handle
Door
Axle
Wheel
Handle
Door
Axle
Wheel
Handle
Door
Axle
Wheel
Handle
Door

10
20
10
40
10
20
10
40
10
20
10
40
10
20
10
40
10
20
10
30

Answer: A

19.SELECT * FROM a
LEFT OUTER JOIN b ON a.name = b.name
What result set is returned by the sample code above if both a.name and
b.name allow NULL values?
Options:
A. All rows from a and any matching rows from b, including those in which
b.name IS NULL, where there is no matching row from b, NULL values are
returned.
B. All non-NULL rows from a and any non-NULL rows from b that match a
non-NULL value from a.
C. All non-NULL matching rows from both tables, plus non-NULL rows from a
matched with NULL values from b, plus non-NULL rows from b matched
with NULL values from a.

D. All rows from a and any non-NULL rows from b that match a non-NULL
value from a; where there is no matching row from b, NULL values are
returned for b columns.
E. All non-NULL rows from a and any non-NULL rows from b that match a
non-NULL value from a, where there is no matching row from b, NULL
values are returned.
Answer: D
20.

----EMP---NAME
Sam
Alex
David

SALARY
33000
28000
35000

DEPT
10
20
30

---1---SELECT name AS Last_Name, salary AS sal, dept


FROM emp
---2---SELECT name AS Last Name, salary AS sal, dept
FROM emp
---3--SELECT name AS Last Name, salary AS sal, dept
FROM emp
---4--SELECT name AS Last Name, salary AS sal, dept
FROM emp
---5--SELECT name AS [Last Name], salary as sal, dept
FROM emp
Which of the above SELECT statements return 3 rows of output?
Options:
A.
B.
C.
D.
E.

1,
2,
1,
1,
2,

3, 5
5
3, 4
4
3, 5

Answer: D
21. t_ const
c1

c2

c3

c4

c5

------------- ----------- - -------------0


NULL
-1.32
Good Morning
1
SELECT COALESCE (c2, 3, c5), FLOOR(c3 * -1),
ROUND (c3, 2), ROUND(c1,2),
SUBSTRING (c4, 7, LENGTH (c4))
FROM t_const
Referring to the t_const table above, what result does the query return?
Options:
A. 3

1.0

-1.30

0.00

orning

B. 3

1.0

-1.32

0.0

Morning

C. 1

-1.30

0.0

orning

D. 3

-1.30

0.0

Morning

E. 3

-1.32

0.0

orning

Answer: E
22. ----DATA---COL1
--------1
1
1
1

COL2
---------1
NULL
NULL
1

SELECT * FROM data


WHERE col1 = col2 OR

COL3
--------1
1
NULL
NULL
col2 = col3

Referring to the above, how many rows does the SELECT statement return?
Options:
A.
B.
C.
D.
E.

0
1
2
3
4

Answer: C

23.In the SQL language, how do you signify that you wish to make a related
series of changes to database data in which either all should be made
permanent or none should?
Options:
A. Begin a new transaction
B. Instruct the database server to perform a checkpoint
C. Instruct the database server to release all data locks.
D. Drop all temporary tables.
E. Begin a new session
Answer: B
24.

Eateries

eno
----1
2
3
4

name
-------------Quick and Dirty
Low Bucks
Jeffy Grease
Stuffed Stuff

dishno
----------1
2
3
4
5
6
7

MenuGuide
eno
---------1
1
2
3
3
4
4

SELECT name AS eatery, phone


FROM Eateries
WHERE EXISTS
(SELECT m1. *

phone
-------------1112223333
1112224444
1114443333
1112225555

course

Price

whatever
hash noodles
smashed potato
small potatoes
singing beans
fishy stuff
square pizza

3.00
15.00
20.00
4.00
3.00
NULL
5.00

FROM MenuGuide m1
WHERE m1.price <
(SELECT AVG(m2.price)
FROM MenuGuide m2)
AND m1.eno = Eateries.eno)
Referring to the tables above, how many distinct eateries does the query
return?
Options
A. 1
B. 2
C. 3
D. 4
E. 12
Answer: C
25. ----1---UPDATE table2 SET name=N/A
-----2----COMMIT
-----3---INSERT INTO table2 values (1)
-----4----DELETE FROM table2
Referring to the above, which SQL statements signify the end of one
transaction and the beginning of another?
Options:
A.
B.
C.
D.
E.

1,2,4
2,4
1,2,3,4,5
1,3,5
2,3,5

Answer: A
26.CREATE
INSERT
INSERT
INSERT

TABLE test1 (cpk INT PRIMARY KEY)


INTO test1 VALUES(1)
INTO test1 VALUES(2)
INTO test1 VALUES(3)

CREATE TABLE test2 (ifk INT REFERENCES test1(cpk) ON DELETE


CASCADE)
INSERT INTO test2 VALUES(1)
INSERT INTO test2 VALUES(2)
INSERT INTO test2 VALUES(3)
INSERT INTO test2 VALUES(2)
INSERT INTO test2 VALUES(1)
DELETE FROM test1 WHERE cpk <> 2
Referring to the above scenario, what is the result of the select statement?
Options:
A. 2
2
B. 1
2
3
1
C. 1
2
3
2
1
D. 1
3
1
E. 1
3
2
1
Answer: A
27.t1
c1
-------------1
2
4
t2
c1
---------------

1
3
2
SELECT * FROM t1 FULL JOIN t2 ON t1.c1=t2.c1
What is the result of the query in the tables above?
Options:

A.

B.

C.

D.

E.

c1
1
NULL
2
4

c1
1
3
2
NULL

c1
1
1
1
2
2
4

c1
1
3
2
3
2
NULL

c1
1
2
4

c1
1
2
NULL

c1
1
2
2
4
4
4

c1
1
1
2
1
3
2

c1
1
NULL
2

c1
1
3
2

Answer: A

28.---EMP---NAME
Ben
Sam
Alex
David
Rock
Bayer
Traven

SALARY
30000
28000
35000
32000
24000
28000
20000

DEPT
10
20
30
10
20
10
40

SELECT sum(ac(salary))
FROM emp
WHERE dept IN (10,20)
GROUP BY dept
What value does the above table return?
Options:
A.
B.
C.
D.
E.

28000
28400
56000
71000
142000

Answer: B
29.

---EMP--NAME
---------------Ben
Alex
Sam
David

SALARY
------------------36000
24000
42000
30000

DEPT
--------------10
20
30
10

----- OUTPUT-------Position Last Name


-----------------------------Employee Ben
Employee Alex
Employee Sam
Employee
David

Monthly Salary
-----------------------3000
2000
3500
2500

Department
-----------------------10
20
30
10

Given the above EMP table, which SELECT statement produces the
output shown?

Options:
A. SELECT Employee AS Position, name AS Last Name
Salary / 12 AS Monthly Salary, dept AS Department
FROM emp
B. SELECT Employee AS Position, name AS Last Name
Salary / 12 AS Monthly Salary, dept AS Department
FROM emp
C. SELECT Employee AS Position, name AS Last Name
Salary / 12 AS Monthly Salary, dept AS Department
FROM emp
D. SELECT Employee AS Position, name AS Last Name
Salary / 12 AS Monthly Salary, dept AS Department
FROM emp
E. SELECT Employee AS Position, name AS Last Name
Salary / 12 AS Monthly Salary, dept AS Department
FROM emp
Answer: B
30.SELECT COUNT(b.title)
FROM books b
WHERE b.genre = Horror
AND b.title IS NULL
Why does the above query fail to find an accurate count from the books
table in which the title is missing for a specific genre?
Options:
A. The COUNT(b.title) function does not count NULL values in that field
B. This query never returns a value higher than 1 because the
COUNT(b.title) function counts the unique values.
C. The proper syntax for the last line of the query is HAVING b.title is NULL.
D. The conditions in the WHERE clause need to be reversed. Otherwise, all
Horror titles (NULL or non-NULL) will be included
E. The proper syntax for the last line of the query is HAVING b.title AS NULL.
Answer: A
31.

Table Name: Products


Categor
y
indoor
outdoor
Indoor
outdoor

Type

Price

Kitchen
garden
bathroom
garden

1.50
6.00
4.75
20.20

indoor
office

bathroom
desktop

4.25
9.80

SELECT category, COUNT(DISTINCT type)


FROM products
GROUP BY category
How many rows does the above SQL statement return?
Options:
A. One row
B. Two rows
C. Three rows
D. Four rows
E. Five rows
Answer: C
32.CREATE
INSERT
INSERT
INSERT
CREATE
INSERT
INSERT
INSERT
INSERT
INSERT

TABLE test1
INTO test1
INTO test1
INTO test1

(cpk INT PRIMARY KEY)


VALUES(NULL)
VALUES(0)
VALUES(0)

TABLE test2 (ifk INT REFERENCES test1 (cpk)


INTO test2 VALUES(NULL)
INTO test2 VALUES(NULL)
INTO test2 VALUES(1)
INTO test2 VALUES(0)
INTO test2 VALUES(0)

SELECT * FROM test2


Referring to the above, what results if all of the statements are run?
Options:
A. NULL
1
0
0
B. NULL
1
0
C. NULL
0
0
D. NULL
NULL
1

0
0
E. NULL
NULL
0
0
Answer: E
33. t1
c1
----------1
2

c2
----------1
2

t2
c1
-----------1
3
Result
c1
-----1
2

c2
-----------3
3
c2
-----1
2

c1
------1
3

c2
-------1
3

Which query do you run in order to obtain the result in the above table?
Options:
A. select from t1 left outer join t2 on t1.c1=t2.c1
B. select from t1 full join t2 on t1.c1=t2.c1
C. select from t1 right outer join t2 on t1.c1=t2.c1
D. select from t1 full join t2
E. select from t1 left outer join t2 on t1.c1<=t2.c1
Answer: B
34. ---Products--NAME
PRICE
--------------------Hammer
NULL
Screwdriver
NULL
Saw
2.00
Chisel
3.00
Ruler
3.00
Level
4.00

Plane
Knife

5.00
7.00

SELECT AVG(price)
FROM products
What is the result of running the SQL code above?
Options:
A. An error occurs.
B. 2,4
C. 3
D. 4
E. 4,2
Answer: D
35.

t_const
c1
-------0

c2
--------NULL

c3
--------1.32

c4
c5
--------------------------Good Morning
1

SELECT COALESCE(c2, 3,c5), FLOOR(c3 * -1),


ROUND(c3, 2), ROUND(c1,2),
SUBSTRING(c4, 7, LENGTH(c4))
FROM t_const
Referring to the t_const table above, what result does the query return?
Options:
A. 3
B. 3
C. 1
D. 3
E. 3

1.0
1
1
1
1.0

-1.30
-1.30
-1.30
-1.32
-1.32

0.00
0.0
0.0
0.0
0.0

ornng
Morning
orning
orning
Morning

Answer: D

36.

---EMP--NAME

David
Sam
Alex
John
Bayer
Charles
Traven
Greg
Ian

36000
24000
42000
30000
24000
30800
20000
20000
35000

SALARY
10
20
30
10
20
10
40
50
60

DEPT
-------------

----------

-----------

SELECT name, salary, dept


FROM emp e
WHERE NOT EXISTS (SELECT 1
FROM emp
GROUP by dept
HAVING AVG (salary) >
(SELECT AVG (salary)
FROM emp)
)
Referring to the above scenario, which employees are retrieved from the EMP
table?
Options:
A. All employees who work for a department that has an average salary higher
than the average salary
of all employees.
B. All employees who work for a department that has an average salary lower
than or equal to the average salary of department with more than one
employee.
C. All employees who work for a department that has an average salary higher
than the average salary of departments with more than one employee.
D. All employees who work for a department that has an average salary higher
than the average salary of departments with one employee
E.
All employees who work for a department that has an average salary lower
than or equal to the average salary of all employees.
Answer: A
37.
row_id
1
2
3
4
5
6

Table Name: animals


family
mammal
mammal

animal
dog
zebra

Color
Brown
Black &
white
SELECT family, color
fish
shark
Gray
FROM animals
bird
cardinal
red
ORDER BY family,
bird
pelican
White
color DESC
fish
trout
gray
What are the contents of the first row returned by the above query?

Options:
A. bird, red
B. mammal, black & white
C. mammal, brown
D. fish, gray
E. bird, white
Answer: E
38. BUS
vid
----------1
2
3
4
5
Car
vid
--------10
20
30
40

seats
---------10
20
10
40
10

age
--------10
4
6
6
NULL

seats
-------4
10
10
8

age
--------6
4
4
10

1
DELETE FROM bus b, car c WHERE c.seats >= b.seates AND c.age <= b.age
2
DELETE FROM car c WHERE EXISTS (SELECT b.* FROM bus b WHERE b.seats >=
c.seats AND b.age <=
c.age)
3
DELETE FROM bus b WHERE EXISTS (SELECT c.* FROM car c WHERE c.seats >=
b.seats AND c.age <=
b.age)
4
DELETE FROM bus b WHERE vid IN (SELECT DISTINCT b1.vid FROM bus b1, car
c1 WHERE c1.seats
>= b1.seats AND c1.age <= b1.age)
Referring to the tables above, which two statements delete the same rows?
Options:
A. 1, 4
B. 2, 3
C. 3, 4
D. 1, 3
E. 1, 2

Answer: D
39.

---EMP---

NAME
-------------David
30000
Sam
28000
Alex
35000
John
32000
Bayer
24000
Charles
28000
Traven
20000

SALARY
-----------10
20
30
10
20
10
40

DEPT
------------

DELETE FROM emp


WHERE dept NOT IN
(SELECT dept FROM EMP
GROUP BY dept
HAVING AVG(salary) >
(SELECT AVG (salary) FROM emp)
)
In the above scenario, which rows of the EMP table are deleted?
Options:
A. Rows where the employee works for a department that has an average
salary greater than the average salary for all employees.
B. Rows where the employees works for a department that has an average
salary less than or equal to the average salary for all employees.
C. Rows where the employee has a salary less than or equal to the average
salary for all employees.
D. Rows where the employee has a salary greater than the average salary for
all employees.
E. Rows where the employee works for a department that has an average
salary not equal to the average salary for all employees.
Answer: A
40. ----DATA---COL1
----------1
1
1

COL2
-----------1
NULL
NULL

COL3
-------------1
1
NULL

NULL

SELECT * FROM data


WHERE col1 = col2 OR col2 = col3
Referring to the above, how many rows does the SELECT statement return?
Options:
A. 0
B. 1
C. 2
D. 3
E. 4
Answer: D
41.

Eateries
eno
-------1
2
3
4

name
------------------Quick and Dirty
Low Bucks
Jeffy Grease
Stuffed Stuff

phone
--------------1112223333
1112224444
1114443333
1112225555

Menu Guide
dishcod
e
-----------1
2
3

eno
---------

course
-----------------

price
--------------

1
1
2

3.00
15.00
20.00

4
5
6
7

3
3
4
4

whatever
hash noodles
smashed
potato
small potatoes
singing beans
fishy stuff
square pizza

4.00
3.00
NULL
5.00

SELECT name AS eatery, phone


FROM Eateries
WHERE EXISTS
(SELECT m1.*
FROM MenuGuide m1
WHERE m1.price <
(SELECT AVG(m2.price) FROM MenuGuide m2) AND
M1.eno = Eateries.eno)

Referring to the tables above, what result set does the query produce?
Options:
A.
Quick and
Dirty
Jeffy Grease
Stuffed Stuff

111222
3333
111444
3333
111222
5555

B.

Quick and
Dirty
Jeffy Grease
Low Bucks

111222
3333
111444
3333
111222
4444

C.

Quick and
Dirty
Jeffy Grease
Low Bucks
Stuffed Stuff

111222
3333
111444
3333
111222
4444
111222
5555

D.

E.

Quick and
Dirty
Low Bucks
Stuffed Stuff

Jeffy Grease
Stuffed Stuff

111222
3333
111222
4444
111222
5555
111444
3333
111222
5555

Answer: C
42.
2
3
4
5
6
7

1 SELECT bus_name, profits


From business
Where city =
(SELECT city FROM locations
Where city LIKE Alban%
AND state = NY
ORDER BY profits DESC

How do you modify the sample code above if you


want to avoid causing an error if the subquery re
turns more than one row?

Options:
A. Change line 1 to read SELECT DISTINCT
bus_name, profits
B. Change line 3 to read WHERE city = ANY
C. Change line 4 to read (SELECT DISTINCT city FROM locations
D. Change line 5 to read WHERE MAX(city) LIKE Alban%
E. Change line 7 to read ORDER BY city, profits DESC
Answer: B
43. DELETE FROM doctors d, physicians p

WHERE d.doc_id = p.phys_id


AND d.house_calls = N
AND p.fee >
(SELECT MAX(gnp) FROM countries
WHERE world = 3)
What happens when the above code is run on the doctors and physicians
tables?
Options:
A. All rows from both tables are deleted because of an improper join between doctors and
physicians.
B. The corresponding rows are deleted from the doctors table because it is listed first, but
the physicians table remains unaffected.
C. Nothing happens to either table because an error is caused by the inclusion of more than
one table in the DELETE statement.
D. The corresponding rows are deleted from both the doctors table and the physicians
table.
E. Nothing happens to either table because an error is caused by the use of a subquery in
the WHERE clause of the DELETE statement.
Answer: C
44.

EMP
emp no
----------10
20
30
40
50
60

dept no lastname
----------- --------------100
Wise
120
Fair
100
Glassman
120
Lawn
100
Wolfson
100
Oakland

age
--------20
20
NULL
20
60
NULL

salary
----------22.00
24.00
51.00
18.00
50.00
60.00

DELETE FROM emp


WHERE age <
(SELECT AVG(age) FROM emp WHERE empno <> 30)
AND deptno BETWEEN 100 and 130
Referring to the table above, how many rows does the statement delete?
Options:
A. Two
B. Three
C. Four

D. Five
E. Six
Answer: B
45. In the SQL language, how do you signify that you wish to make a related series of changes to
database data in which either all should be made permanent or none should?
Options:
A. Begin a new session
B. Begin a new transaction
C. Drop all temporary tables
D. Instruct the database server to release all data locks.
E. Instruct the database server to perform a checkpoint
Answer: E
46. CREATE TABLE dept (
deptno INT
location VARCHAR (20)
serverId CHA (8)
)

DEFAULT 99 NOT NULL PRIMARY KEY,


DEFAULT Southfield,
DEFAULT ABCO

CREATE TABLE emp (


empno INT NOT NULL PRIMARY KEY,
deptno INT NOT NULL REFERENCES dept (deptNO) ON DELETE
RESTRICT,
firstname CHAR (20),
lastname CHAR (20)
)
1
INSERT
2
INSERT
3
INSERT
4
INSERT

INTO emp values (10, NULL, Sol, Wise)


INTO emp values (20, 120, Tom, Thomson)
INTO dept values (120, Birmingham, ABC2l)
INTO dept values (NULL, Birmingham, ABC2l)

After tables Dept and Emp are created using the CREATE statements above, which
sequence of INSERT statements succeeds?
Options:
A. 2, 3
B. 3, 2
C. 4, 1
D. 2, 4
E. 4, 2

Answer: B
47.
types
animals
family
blood_type
Name
mammal
warm-blooded
mammal dog
SELECT DISTINCT name FROM animals
fish
cold-blooded
mammal
lion
a, types t
bird
cold-blooded
fish
guppy
WHERE a.family = t.family
bird
eagle
reptile
How many
rows aresnake
returned by the query above?
bird
pelican
fish
guppy
Options:
A. Zero rows
B. One row
C. Three rows
D. Five rows
E. Six rows
Answer: D
48.

----BIGTABLE----

COL1
COL2
COL3
COL4
COL5
COL6
-------------------- --------- ---------- ---------- --------1
2
3
4
5

SELECT col1 -- omit ,col2--- omit ,col3-- ,col4


/*
,col5
/*
--include
/*
,col6
*/
FROM bigtable
Referring to the above, how many columns does the SELECT statement return?
Options:
A. 1
B. 2
C. 3
D. 4
E. 5
Answer: D

49. ----BIGTABLE--------COL1
----------1

COL2
--------2

COL3
COL4
COL5
COL6
--------- -------- -------- ---------3
4
5

SELECT col1, --col2, col3 -- col4,


/*
col5,
*/
col6
FROM bigtable
Referrring to the above, how many columns does the SELECT statement
return?
Options:
A. 2
B. 3
C. 4
D. 5
E. 6
Answer: B
50.

Eateries:
eno
----------1
2
3
4
MenuGuide
dishnno
------------1
2
3

name
--------------------Quick and Dirty
Starve Bucks
JeffyGrease
Stuffed Stuff
eno
-----------1
1
2

5
6
7

3
4
4

phone
---------------1112223333
1112224444
1114443333
1112225555

eateryname
---------------------asis
hash noodles
smashed
potato
small
potatoes
singing beans
fishy stuff
the last
supper

price

3.00
15.00
20.00
4.00
3.00
10.00
NULL

SELECT name AS eatery, phone


FROM Eateries
WHERE eno IN
(SELECT eno FROM MenuGuide WHERE price < 5.00)
Referring to the table above, how many eateries does the query return?
Options:
A. ZERO
B. One
C. Two
D. Three
E. Four
Answer: C
51. CREATE TABLE Accounts (
acno INT PRIMARY KEY,
amt DECIMAL (8, 2),
fee_code CHAR (2))
CREATE TABLE Fee_codes(
Fee_code CHAR (2) PRIMARY KEY,
descr CHAR (20))
1
ALTER TABLE Accounts ADD CONSTRAINT FK_Accounts
FOREIGN KEY (fee_code) REFERENCES Fee_codes (fee_code)
2
INSERT INTO Accounts Values (10, 220.0, BC )
3
INSERT INTO Accounts Values (20, 330.0, AB )
4
INSERT INTO Fee_codes Values ( AB, aaaaa )
5
INSERT INTO Accounts Values (20, 330.0, AB )
6
ALTER TABLE Accounts DROP CONSTRAINT FK_Accounts
7
INSERT INTO Accounts Values (10, 220.0, BC )
Referring to the scenario above, which of the statements fail if you run the
statements in the given order?
Options:
A. 2, 3
B. 2, 3, 7
C. 2, 3, 4, 5
D. 2, 3, 4, 5, 7
E. 2, 3, 4, 5, 6, 7

Answer: B

Das könnte Ihnen auch gefallen