Database Programming With SQL Midterm Exam
Database Programming With SQL Midterm Exam
Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.
Section 1
(Answer all questions in this section)
1.What command can be used to show information about the structure of Mark for Review
a table? (1) Points
SELECT
DESCRIBE (*)
ALTER
INSERT
Correct
2.What command retrieves data from the database? Mark for Review
(1) Points
INSERT
ALTER
DESCRIBE
SELECT (*)
Correct
3.What language is used to query data in a Relational Database? Mark for Review
(1) Points
C++
BASIC
SQL (*)
Java
Correct
Correct
5.What would you use in the SELECT clause to return all the columns in Mark for Review
the table? (1) Points
Correct.
Correct.
Section 2
(Answer all questions in this section)
11.You need to combine the FIRST_NAME and LAST_NAME columns Mark for Review
in the EMPLOYEES table and display the columns as a combined (1) Points
character string. Which operator should you use?
|
+
|| (*)
AND
Correct.
Section 3
(Answer all questions in this section)
12.Find the clause that will give the same results as: Mark for Review
(1) Points
SELECT *
FROM d_cds
WHERE cd_id NOT IN(90, 91, 92);
Correct
13.A column alias can be specified in an ORDER BY Clause. True or Mark for Review
False? (1) Points
True (*)
False
Correct
Correct.
15.The conversion function TO_CHAR is a single row function. True or Mark for Review
False? (1) Points
True (*)
False
Correct
Section 4
(Answer all questions in this section)
16.You need to display each employee's name in all uppercase letters. Mark for Review
Which function should you use? (1) Points
CASE
UCASE
UPPER (*)
TOUPPER
Correct
17.You query the database with this SQL statement: Mark for Review
(1) Points
SELECT LOWER(SUBSTR(CONCAT(last_name, first_name)), 1,
5) "ID"
FROM employee;
Correct
18.You need to subtract three months from the current date. Which Mark for Review
function should you use? (1) Points
ADD_MONTHS (*)
TO_DATE
MONTHS_BETWEEN
ROUND
Correct
19.ROUND and TRUNC functions can be used with which of the Mark for Review
following Datatypes? (1) Points
Correct
Section 5
(Answer all questions in this section)
Both the YY and RR date formats will interpret the year as 2089
The RR date format will interpret the year as 2089, and the YY
date format will interpret the year as 1989
The RR date format will interpret the year as 1989, and the YY
date format will interpret the year as 2089 (*)
Both the YY and RR date formats will interpret the year as 1989
Correct
Section 5
(Answer all questions in this section)
21.You need to display the HIRE_DATE values in this format: 25th of Mark for Review
July 2002. Which SELECT statement would you use? (1) Points
(*)
SELECT enroll_date(hire_date, 'DDspth "of" Month YYYY')
FROM employees;
SELECT TO_CHAR(hire_date, 'DDTH "of" Month YYYY')
FROM employees;
SELECT TO_CHAR(hire_date, 'DDspth 'of' Month RRRR')
FROM employees;
Correct
22.You have been asked to create a report that lists all customers who Mark for Review
have placed orders of at least $2,500. The report's date should be (1) Points
displayed using this format:
Day, Date Month, Year (For example, Tuesday, 13 April, 2004 ).
Which statement should you issue?
(*)
Correct
23.For the given data from Employees (last_name, manager_id) what is Mark for Review
the result of the following statement: (1) Points
DATA:( King, null
Kochhar, 100
De Haan, 100
Hunold, 102
Ernst, 103)
SELECT last_name,
DECODE(manager_id, 100, 'King', 'A N Other') "Works For?"
FROM employees
King, A N Other
Kochhar, King
De Haan, King
Hunold, A N Other
Ernst, A N Other
(*)
Invalid statement.
King, A N Other
Kochhar, King
De Haan, King
Hunold, Kochhar
Ernst, De Haan
King, Null
Kochhar, King
De Haan, King
Hunold, A N Other
Ernst, A N Other
Correct
24.Which of the following General Functions will return the first non- Mark for Review
null expression in the expression list? (1) Points
COALESCE (*)
NULLIF
NVL
NVL2
Correct
NVL and COALESCE, but not NVL2, can be used with group
functions to replace null values.
COALESCE, but not NVL and NVL2, can be used with group
functions to replace null values.
NVL, NVL2, and COALESCE can be used with group functions
to replace null values. (*)
NVL and NVL2, but not COALESCE, can be used with group
functions to replace null values.
Correct
Section 6
(Answer all questions in this section)
26.You need to join all the rows in the EMPLOYEES table to all the Mark for Review
rows in the EMP_REFERENCE table. Which type of join should you (1) Points
create?
Correct
27.Which of the following conditions will cause an error on a Mark for Review
NATURAL JOIN? (1) Points
Correct
28.You need to join the EMPLOYEE_HIST and EMPLOYEES tables. Mark for Review
The EMPLOYEE_HIST table will be the first table in the FROM (1) Points
clause. All the matched and unmatched rows in the EMPLOYEES
table need to be displayed. Which type of join will you use?
A cross join
A right outer join (*)
An inner join
A left outer join
Correct
DEPARTMENTS Table:
(*)
SELECT d.department_id, e.first_name, e.last_name
FROM employees e
LEFT OUTER JOIN departments d
WHERE (e.department_id = d.department_id);
Correct
30.You can do nonequi-joins with ANSI-Syntax. True or False? Mark for Review
(1) Points
True (*)
False
Correct
Section 6
(Answer all questions in this section)
31.Which of the following database design concepts is implemented Mark for Review
with a self join? (1) Points
Arc
Supertype
Non-Transferability
Recursive Relationship (*)
Correct
(*)
SELECT p.part_id, t.product_id
FROM part p, product t
WHERE p.part_id =! t.product_id;
SELECT p.part_id, t.product_id
FROM part p, product t
WHERE p.part_id = t.product_id (+);
Correct
Section 7
(Answer all questions in this section)
33.Using Oracle Proprietary join syntax, which operator would you use Mark for Review
after one of the column names in the WHERE clause when creating (1) Points
an outer join?
(+) (*)
+
*
=
Correct
34.Oracle proprietary JOINS can use the WHERE clause for conditions Mark for Review
other than the join-condition. True or False? (1) Points
True (*)
False
Correct
35.The PATIENTS and DOCTORS tables contain these columns: Mark for Review
(1) Points
PATIENTS
PATIENT_ID NUMBER(9)
LAST_NAME VARCHAR2 (20)
FIRST_NAME VARCHAR2 (20)
DOCTORS
DOCTOR_ID NUMBER(9)
LAST_NAME VARCHAR2 (20)
FIRST_NAME VARCHAR2 (20)
Correct
Section 8
(Answer all questions in this section)
36.What would the following SQL statement return? Mark for Review
(1) Points
SELECT COUNT(first_name)
FROM employees;
Correct
37.Which group function would you use to display the lowest value in Mark for Review
the SALES_AMOUNT column? (1) Points
MAX
MIN (*)
COUNT
AVG
Correct
Which SELECT statement will return the average price for the 4x4
model?
SELECT AVG(price)
FROM trucks
WHERE model IS '4x4';
SELECT AVG(price)
FROM trucks
WHERE model IS 4x4;
SELECT AVG(price)
FROM trucks
WHERE model = '4x4';
(*)
SELECT AVG(price), model
FROM trucks
WHERE model IS '4x4';
Correct
Section 9
(Answer all questions in this section)
39.GROUPING SETS is another extension to the GROUP BY clause Mark for Review
and is used to specify multiple groupings of data but provide a single (1) Points
result set. True or False?
True (*)
False
Correct
40.If you want to include subtotals and grand totals for all columns Mark for Review
mentioned in a GROUP BY clause, you should use which of the (1) Points
following extensions to the GROUP BY clause?
CUBE (*)
HAVING
GROUP BY ALL COLUMNS
ROLLUP
Correct
Section 9
(Answer all questions in this section)
41.MINUS will give you rows from the first query that are not present in Mark for Review
the second query. (True or False?) (1) Points
True (*)
False
Correct
42.What is the correct order of clauses in a SELECT statement? Mark for Review
(1) Points
SELECT
FROM
WHERE
ORDER BY
GROUP BY
HAVING
SELECT
FROM
WHERE
HAVING
ORDER BY
GROUP BY
SELECT
FROM
HAVING
GROUP BY
WHERE
ORDER BY
SELECT
FROM
WHERE
GROUP BY
HAVING
ORDER BY
(*)
Correct
43.How would you alter the following query to list only employees Mark for Review
where two or more employees have the same last name? (1) Points
SELECT last_name, COUNT(employee_id)
FROM EMPLOYEES
GROUP BY last_name;
(*)
Correct
44.What is the best explanation as to why this SQL statement will NOT Mark for Review
execute? (1) Points
SELECT department_id "Department", AVG (salary)"Average"
FROM employees
GROUP BY Department;
Correct
Section 10
(Answer all questions in this section)
45.Multiple-row subqueries must have NOT, IN, or ANY in the Mark for Review
WHERE clause of the inner query. True or False? (1) Points
True
False (*)
Correct
Section 10
(Answer all questions in this section)
46.The SQL multiple-row subquery extends the capability of the single- Mark for Review
row syntax through the use of which three comparison operators? (1) Points
Correct
Correct
48.Single row subqueries may not include this operator: Mark for Review
(1) Points
<>
=
>
ALL (*)
Correct
49.A correlated subquery is evaluated _____ for each row processed by Mark for Review
the parent statement. (1) Points
EVERY TIME
COMPLETELY
ONCE (*)
Correct
Correct