SQL Quiz

Post on 26-Jan-2016

225 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

fddf

Transcript

1. Table Name: animals

Row_id family animal Color1 Mammal Dog brown2 mammal zebra Black, white3 fish shark gray4 bird gull White5 bird pelican white6 fish trout Gray

SELECT animal From animals ORDER BY animal DESC

What is the value of animal in the first row returned?

Options: A. dogB. sharkC. troutD. pelicanE. zebra

Answer: E

2. SELECT emp_num, years, SUM(salary)FROM salesUNION ALLSELECT emp_id, SUM(takehomepay)FROM marketing

Which of the following problems will not result in an error?

Options:

A. emp_num and emp_id do not match namesB. Aggregate functions need GROUP By clausesC. SUM(salary) and SUM(takehomepay) do not match namesD. UNION ALL queries need the same number of elements in the SELECT clausesE. UNION ALL queries will result in duplicates

Answer: D

3. --- EMP---

NAME SALARY DEPT

--------- ---------- --------Chevalier 30000 10Smith 28000 20Wong 35000 30Hadiz 32000 10Hu 24000 20Travino 28000 10Boyer 20000 40

SELECT nameFROM empWHERE 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. CREATE INDEX emp_perf_idx ON emp(dept)B. CREATE INDEX emp_perf_idx ON emp(name, salary)C. CREATE INDEX emp_perf_idx ON emp(name)D. CREATE INDEX emp_perf_idx ON emp(dept, name)E. CREATE INDEX emp_perf_idx ON emp(dept, salary)

Answer: A

4. Table Name: combosrow_id

a b c

1 cat NULL dog2 lion dog NULL3 NULL bird ferret4 lynx ant bat5 fly bee beetie6 fish fish cricket

SELECT MAX(a), MIN(b), MAX(c) FROM combos

What is returned when the sample code above is expected?

Options:A. lynx NULL ferretB. lynx fish ferretC. NULL NULL NULLD. lynx ant ferretE. lynx bee lion

Answer: D

5. SELECT COUNT(b.title)FROM books bWhere 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 valuesB. 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. Expensesdept type dollar------ ------- -------A P 100A D 0A S 50B P NULLB P 10B D 100B S 500C D 400C S 100

Returnstype ratio------ -------P 2.00S 3.00D 2.00N 5.00

SELECT e.type, SUM(r.ratio*e.dollar)FROM expenses e, returns rWHERE e.type=r.typeGROUP BY e.typeHAVING 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.00S 1950.00

C. D 220.00

D. D 1000.00S 1950.00

E. P 220.00

Answer: E

2. SELECT id, last_name, first_name, salaryFROM employees e, payroll pWHERE 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: Customersrow_id

gender department Purchases

1 female housewares 27.752 male garden 42.203 female home improve-

ment97.50

4 female kitchen/bathroom 28.605 male furniture 225.75

6 female garden 34.407 Male hardware 16.50

SELECT department, COUNT(*) FROM customersWHERE gender LIKE ‘%male’AND purchases > 30.00GROUP BY department ORDER BY 1

How many rows does the above query return?

Options:A. Zero rowsB. Two rowsC. Three rowsD. Four rowsE. Six rows

Answer: C

4. Busvid seats age---- ------- -----1 10 102 20 43 10 64 40 65 10 NULL

carvid seats age---- ------ ------10 4 620 10 430 10 440 8 10

1DELETE FROM bus b, car c WHERE c.seats >=b.seats AND c.age <= b.age2DELETE FROM car c WHERE EXISTS (SELECT b.* FROM bus b WHERE b.seats >= c.seats AND b.age <= c.age)3DELETE FROM bus b WHERE EXISTS (SELECT c.* FROM car c WHERE c.seats >= b.seats and c.age <= b.age)4DELETE 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,3B. 1,2C. 1,4D. 3,4E. 1,3

Answer: D

5. --- EMP---

NAME SALARY DEPT--------- ----------- ---------Smith 32000 20Boyer 20000 40Sawi 38000 60

UPDATE empSET salary = salary * 1.5, dept = salary / 100WHERE salary > (SELECT AVG(salary) from emp)

After the update above, what do the rows of the EMP table contain?

Options:A. Smith 32000 48

Boyer 20000 40Sawi 38000 57

B. Smith 48000 48Boyer 20000 40Sawi 57000 57

C. Smith 32000 20Boyer 20000 40Sawi 38000 60

D. Smith 48000 32Boyer 20000 40Sawi 57000 38

E. Smith 48000 32Boyer 20000 20Sawi 57000 38

Answer: D

6. T1

cno cnt------ ------1 11 22 13 43 53 94 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. TwoB. ThreeC. FourD. FiveE. 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 salaryD. 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_id family animal color1 mam-

maldog brown

2 mam-mal

zebra black & white

3 fish shark gray4 bird cardinal red5 bird pelican white6 fish trout 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, whiteB. fish, grayC. mammal, black & whiteD. bird, redE. mammal, brown

Answer: A

9. ----EMP----

NAME SALARY DEPTJames 35000 10Jones 22000 20Christopher 21000 30John 34000 10

Andrew 48000 20Ricky 54000 10Mathews 32000 40Adam 20000 50Jennifer 24000 60

SELECT name, salary, deptFROM emp eWHERE 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. WHERE name like ‘SH%’B. WHERE name like SOUNDEX(‘SHOOLS’)C. WHERE name = SOUNDEX(‘SHOOLS”)D. WHERE name like ‘%SH%’

OR name like ‘CH%’E. WHERE SOUNDEX(name) = SOUNDEX(‘SHOOLS”)

Answer: E

11. emp

CREATE TABLE emp2 (empno INT,

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

INSERT INTO emp2SELECT * FROM empWHERE job NOT LIKE ‘w%’

Referring to the scenario above, what data does table emp2 contain after the SQL statements are run?

Options:A. 10

203010

AAA AAA

BAAZZZ

analyst salesrep

dbawebmaster

80000.0060000.00 50000.0040000.00

.0010000.001000.0050000.00

B. 102030

AAAAAABAA

analystsalesrepdba

80000.0060000.0050000.00

.0010000.001000.00

C. 10203030

AAAAAABAABAA

analystsalesrepdbawebmaster

80000.0060000.0050000.0040000.00

.0010000.001000.0050000.00

D. 10203060

AAAAAABAACCC

analystsalesrepdbaNULL

80000.0060000.0050000.0030000.00

.0010000.001000.0050000.00

E. 20 AAA salesrep 60000.00 10000.00

empno---------

dept-------

job-------

salary---------

comm----------

10 AAA analyst 80000.00 .0020 AAA salesrep 60000.00 10000.0030 BAA dba 50000.00 1000.0040 BAA webmaster 40000.00 50000.0050 ZZZ webmaster 40000.00 60000.0060 CCC NULL 30000.00 60000.00

3060

BAACCC

dbaNull

50000.0030000.00

1000.0050000.00

Answer: B

12. HR

emp_id-----------

dept--------

sex------

sal------

1 A M 80000.003 A F 20000.004 A F 25000.005 B M 50000.006 B F 60000.008 C F 90000.009 D M 70000.0010 E M 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. AB. BC. CD. DE. E

Answer: B

13. CUSTcust name Owes_10 Tim 20.0020 Sam 30.0030 David NULL40 Alex .0050 Greg 40.00

CREATE VIEW v_customer ASSELECT * FROM customer

WHERE owes_us > (SELECT AVG(owes_us) FROM customer)

UPDATE v_customer SET owes_us =CASE WHEN owes_us > 5THEN owes_us – 5ELSE 0END

How does the above table look after the view update?

Options:

A. 10204050

TimSamAlexGreg

15.0025.00.0035.00

B. 1020304050

TimSamDavidAlexGreg

15.0025.00NULL.0035.00

C. 1020304050

TimSamDavidAlexGreg

20.0025.00NULL.0035.00

D. 1020304050

TimSamDavidAlexGreg

20.0030.00NULL.0040.00

E. 10204050

TimSamAlexGreg

20.0025.00.0035.00

Answer: C

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 fileB. Instruct the database to create a savepoint

C. Instruct the database to begin a new transactionD. Open a separate session to the database serverE. 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’

UNIONSELECT f1, f2 FROM test WHERE f2 = ‘1’

B. CREATE VIEW v ASSELECT f1, f2 FROM test WHERE f1 =’1’UNIONSELECT f1, f2 FROM test WHERE f2 =’1’

CREATE INDEX v_ind ON v(f1,f2)

SELECT f1, f2 FROM v

C. CREATE VIEW v1 ASSELECT f1, f2 FROM test WHERE f1 =’1’UNIONSELECT f1, f2 FROM test WHERE f2 = ‘1’

SELECT f1, f2 FROM v1CREATE TABLE tmp(f1 char(1), f2 char(1)

D. INSERT INTO tmpSELECT 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 SALARY DEPTVicky 36000 10Haider 30000 10

Tom 33000 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 $KFROM 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 TABLE test5 (c INT UNIQUE REFERENCES test1 (ipk))INSERT INTO test5 VALUES (NULL)INSERT INTO test5 VALUES (1)INSERT INTO test5 VALUES (0)INSERT 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. NULL1001

C. NULL10

D. NULL00

E. NULL0

Answer: E

18. Part

Suppl

Part_Suppl

pno name price1 Axle 200.002 Wheel 100.003 Handle 10.004 Door 300.00

sno Name1 Detroit12 Detroit23 Orlando4 Flin

sno pno cnt1 1 101 2 202 3 103 4 303 4 10

SELECT s.name AS supplier, p.name AS part, cntFROM (SELECT sno, pno, SUM(cnt) AS cnt FROM part_suppl GROUP BY sno, pno) AS ps, suppl s, part pWHERE p.pno = ps.pno and s.sno = ps.snoReferring to the tables above, what is the result set of the query?

Options:

Answer: A

19. SELECT * FROM aLEFT 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”.

A. Detroit 1Detroit 2Detroit 2Orlando

AxleWheelHandleDoor

10201040

B. Detroit 1Detroit 1FlintOrlando

AxleWheelHandleDoor

10201040

C. Detroit 1Detroit 1Detroit 2Orlando

AxleWheelHandleDoor

10201040

D. WindsorDetroit 1Detroit 2Orlando

AxleWheelHandleDoor

10201040

E. Detroit 1Detroit 1Detroit 2Orlando

AxleWheelHandleDoor

10201030

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 SALARY DEPTSam 33000 10Alex 28000 20David 35000 30

---1----SELECT name AS Last_Name, salary AS sal, deptFROM emp---2----SELECT name AS Last Name, salary AS sal, deptFROM emp

---3---SELECT name AS ‘Last Name”, salary AS sal, deptFROM emp

---4---SELECT name AS “Last Name”, salary AS sal, deptFROM 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. 1, 3, 5B. 2, 5C. 1, 3, 4D. 1, 4E. 2, 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 -1.30 0.0 orning

D. 3 1 -1.30 0.0 Morning

E. 3 1 -1.32 0.0 orning

Answer: E

22. ----DATA----

COL1 COL2 COL3--------- ---------- ---------1 1 11 NULL 11 NULL NULL1 1 NULL

SELECT * FROM dataWHERE col1 = col2 OR col2 = col3

Referring to the above, how many rows does the SELECT statement return?

Options:

A. 0

B. 1C. 2D. 3E. 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 transactionB. Instruct the database server to perform a checkpointC. Instruct the database server to release all data locks.D. Drop all temporary tables.E. Begin a new session

Answer: B

24. Eateries

MenuGuide

SELECT name AS eatery, phone

eno-----

name--------------

phone--------------

1 Quick and Dirty 11122233332 Low Bucks 11122244443 Jeffy Grease 11144433334 Stuffed Stuff 1112225555

dishno-----------

eno----------

course Price

1 1 whatever 3.002 1 hash noodles 15.003 2 smashed potato 20.004 3 small potatoes 4.005 3 singing beans 3.006 4 fishy stuff NULL7 4 square pizza 5.00

FROM EateriesWHERE 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, how many distinct eateries does the query return?

OptionsA. 1B. 2C. 3D. 4E. 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 begin-ning of another?

Options:

A. 1,2,4B. 2,4C. 1,2,3,4,5D. 1,3,5E. 2,3,5

Answer: A

26. CREATE TABLE test1 (cpk INT PRIMARY KEY)INSERT INTO test1 VALUES(1)INSERT INTO test1 VALUES(2)INSERT 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. 22

B. 1231

C. 12321

D. 131

E. 1321

Answer: A

27. t1

c1--------------12 4

t2

c1---------------132

SELECT * FROM t1 FULL JOIN t2 ON t1.c1=t2.c1

What is the result of the query in the tables above?

Options:

A. c11NULL24

c1132NULL

B. c1111224

c113232NULL

C. c1124

c112NULL

D. c112

c111

2444

2132

E. c11NULL2

c1132

Answer: A

28. ---EMP----

NAME SALARY DEPTBen 30000 10Sam 28000 20Alex 35000 30David 32000 10Rock 24000 20Bayer 28000 10Traven 20000 40

SELECT sum(ac(salary))FROM empWHERE dept IN (10,20)GROUP BY dept

What value does the above table return?

Options:

A. 28000B. 28400C. 56000D. 71000E. 142000

Answer: B

29. ---EMP--- NAME SALARY DEPT ---------------- ------------------- ---------------

Ben 36000 10

Alex 24000 20Sam 42000 30David 30000 10

----- OUTPUT--------

Position Last Name Monthly Salary Department------------------------------ ------------------------ ------------------------

Employee Ben 3000 10Employee Alex 2000 20Employee Sam 3500 30Employee David 2500 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 bWHERE 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 includedE. The proper syntax for the last line of the query is “HAVING b.title AS NULL.”

Answer: A

31. Table Name: Products

Category Type Priceindoor Kitchen 1.50outdoor garden 6.00Indoor bathroom 4.75outdoor garden 20.20indoor bathroom 4.25office desktop 9.80

SELECT category, COUNT(DISTINCT type) FROM products GROUP BY category

How many rows does the above SQL statement return?

Options:A. One rowB. Two rowsC. Three rowsD. Four rowsE. Five rows

Answer: C

32. CREATE TABLE test1 (cpk INT PRIMARY KEY)INSERT INTO test1 VALUES(NULL)INSERT INTO test1 VALUES(0)INSERT INTO test1 VALUES(0) CREATE TABLE test2 (ifk INT REFERENCES test1 (cpk)INSERT INTO test2 VALUES(NULL) INSERT INTO test2 VALUES(NULL) INSERT INTO test2 VALUES(1) INSERT INTO test2 VALUES(0) INSERT INTO test2 VALUES(0) SELECT * FROM test2

Referring to the above, what results if all of the statements are run?

Options:A. NULL

100

B. NULL10

C. NULL00

D. NULLNULL100

E. NULLNULL00

Answer: E

33. t1

c1 c2----------- -----------1 12 2

t2

c1 c2------------ ------------1 33 3

Resultc1 c2 c1 c2------ ------ ------- --------1 1 1 12 2

3 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.c1B. select “from t1 full join t2 on t1.c1=t2.c1C. select “from t1 right outer join t2 on t1.c1=t2.c1D. select “from t1 full join t2E. select “from t1 left outer join t2 on t1.c1<=t2.c1

Answer: B

34. ---Products---NAME PRICE----------- -----------Hammer NULLScrewdriver NULLSaw 2.00Chisel 3.00Ruler 3.00Level 4.00Plane 5.00Knife 7.00

SELECT AVG(price)FROM products

What is the result of running the SQL code above?

Options:A. An error occurs.B. 2,4C. 3D. 4E. 4,2

Answer: D

35. 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 ornngB. 3 1 -1.30 0.0 MorningC. 1 1 -1.30 0.0 orningD. 3 1 -1.32 0.0 orningE. 3 1.0 -1.32 0.0 Morning

Answer: D

36. ---EMP--- NAME SALARY DEPT ------------- ---------- -----------

SELECT name, salary, deptFROM 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 av-

erage salary of department with more than one employee.

David 36000 10Sam 24000 20Alex 42000 30John 30000 10Bayer 24000 20Charles 30800 10Traven 20000 40Greg 20000 50Ian 35000 60

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 av-erage salary of all employees.

Answer: A

37. Table Name: animals

SELECT family, colorFROM animalsORDER BY family, color

DESC

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. BUSvid seats age----------- ---------- ---------1 10 102 20 43 10 64 40 65 10 NULL

Car vid seats age--------- -------- ---------10 4 620 10 430 10 440 8 10

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

row_id family animal Color1 mammal dog Brown2 mammal zebra Black & white3 fish shark Gray4 bird cardinal red5 bird pelican White6 fish trout gray

2DELETE FROM car c WHERE EXISTS (SELECT b.* FROM bus b WHERE b.seats >= c.seats AND b.age <= c.age)3DELETE FROM bus b WHERE EXISTS (SELECT c.* FROM car c WHERE c.seats >= b.seats AND c.age <= b.age)4DELETE 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, 4B. 2, 3C. 3, 4D. 1, 3E. 1, 2

Answer: D

39. ---EMP---

NAME SALARY DEPT-------------- ------------ ------------

DELETE FROM empWHERE dept NOT IN

(SELECT dept FROM EMPGROUP BY deptHAVING 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.

David 30000 10Sam 28000 20Alex 35000 30John 32000 10Bayer 24000 20Charles 28000 10Traven 20000 40

C. Rows where the employee has a salary less than or equal to the average salary for all employ-ees.

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 COL2 COL3----------- ------------ --------------1 1 11 NULL 11 NULL NULL1 1 NULL

SELECT * FROM dataWHERE col1 = col2 OR col2 = col3

Referring to the above, how many rows does the SELECT statement return?

Options:A. 0B. 1C. 2D. 3E. 4

Answer: D

41. Eateries

eno--------

name-------------------

phone---------------

1 Quick and Dirty 11122233332 Low Bucks 11122244443 Jeffy Grease 11144433334 Stuffed Stuff 1112225555

Menu Guide

dishcode-------------

eno----------

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

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

1 1 whatever 3.002 1 hash noodles 15.00

3 2 smashed potato 20.004 3 small potatoes 4.005 3 singing beans 3.006 4 fishy stuff NULL7 4 square pizza 5.00

SELECT name AS eatery, phone FROM EateriesWHERE EXISTS (SELECT m1.*

FROM MenuGuide m1WHERE m1.price < (SELECT AVG(m2.price) FROM MenuGuide m2) ANDM1.eno = Eateries.eno)

Referring to the tables above, what result set does the query produce?

Options:

Answer: C

42. 1 SELECT bus_name, profits2 From business3 Where city =4 (SELECT city FROM locations5 Where city LIKE ‘Alban%’6 AND state = ‘NY’

A. Quick and DirtyJeffy GreaseStuffed Stuff

111222333311144433331112225555

B. Quick and DirtyJeffy GreaseLow Bucks

111222333311144433331112224444

C. Quick and DirtyJeffy GreaseLow BucksStuffed Stuff

1112223333111444333311122244441112225555

D. Quick and DirtyLow BucksStuffed Stuff

111222333311122244441112225555

E. Jeffy GreaseStuffed Stuff

11144433331112225555

7 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 pWHERE 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-----------

dept no-----------

lastname---------------

age---------

salary-----------

10 100 Wise 20 22.0020 120 Fair 20 24.0030 100 Glassman NULL 51.0040 120 Lawn 20 18.00

50 100 Wolfson 60 50.0060 100 Oakland NULL 60.00

DELETE FROM empWHERE 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. TwoB. ThreeC. FourD. FiveE. 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 sessionB. Begin a new transactionC. Drop all temporary tablesD. 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 DEFAULT 99 NOT NULL PRIMARY KEY,location VARCHAR (20) DEFAULT ‘Southfield’,serverId CHA (8) 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) )

1INSERT INTO emp values (10, NULL, ‘Sol’, ‘Wise’)2INSERT INTO emp values (20, 120, ‘Tom’, ‘Thomson’)

3INSERT INTO dept values (120, ‘Birmingham’, ‘ABC2l’)4INSERT 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, 3B. 3, 2C. 4, 1D. 2, 4E. 4, 2

Answer: B

47.

SELECT DISTINCT name FROM animals a, types tWHERE a.family = t.family

How many rows are returned by the query above?

Options:A. Zero rowsB. One rowC. Three rowsD. Five rowsE. Six rows

Answer: D

48. ----BIGTABLE----

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

animalsfamily Name mammal dogmammal lionfish guppybird eaglereptile snakebird pelicanfish guppy

typesfamily blood_typemammal warm-bloodedfish cold-bloodedbird cold-blooded

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. 1B. 2C. 3D. 4E. 5

Answer: D

49. ----BIGTABLE--------- COL1 COL2 COL3 COL4 COL5 COL6 ----------- --------- --------- -------- -------- ---------- 1 2 3 4 5 6

SELECT col1, --col2, col3 -- col4,/* col5,*/ col6FROM bigtable

Referrring to the above, how many columns does the SELECT statement return?

Options:A. 2B. 3C. 4D. 5E. 6

Answer: B

50. Eateries:eno-----------

name---------------------

phone----------------

1 Quick and Dirty 11122233332 Starve Bucks 11122244443 JeffyGrease 11144433334 Stuffed Stuff 1112225555

MenuGuide

dishnno--------------

eno------------

eateryname-----------------------

price

1 1 asis 3.002 1 hash noodles 15.003 2 smashed potato 20.004 3 small potatoes 4.005 3 singing beans 3.006 4 fishy stuff 10.007 4 the last supper NULL

SELECT name AS eatery, phoneFROM EateriesWHERE eno IN (SELECT eno FROM MenuGuide WHERE price < 5.00)

Referring to the table above, how many eateries does the query return?

Options:A. ZEROB. OneC. TwoD. ThreeE. 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))

1ALTER TABLE Accounts ADD CONSTRAINT FK_Accounts

FOREIGN KEY (fee_code) REFERENCES Fee_codes (fee_code)2INSERT INTO Accounts Values (10, 220.0, ‘BC’ )3INSERT INTO Accounts Values (20, 330.0, ‘AB’ )4INSERT INTO Fee_codes Values ( ‘AB’, ‘aaaaa’ )5INSERT INTO Accounts Values (20, 330.0, ‘AB’ )6ALTER TABLE Accounts DROP CONSTRAINT FK_Accounts7INSERT 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, 3B. 2, 3, 7C. 2, 3, 4, 5D. 2, 3, 4, 5, 7E. 2, 3, 4, 5, 6, 7

Answer: B

top related