Vous êtes sur la page 1sur 16

Database Programming with SQL Midterm

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

4.The SQL SELECT statement is capable of: Mark for Review


(1) Points
Selection and protection
Selection and projection (*)
Projection and updating
None of the above

Correct

5.What would you use in the SELECT clause to return all the columns in Mark for Review
the table? (1) Points

The ALL keyword


A minus sign (-)
A plus sign (+)
An asterisk (*) (*)

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);

WHERE cd_id != 90 or cd_id != 91 or cd_id!= 92;


WHERE cd_id NOT LIKE (90, 91, 92);
WHERE cd_id <=90 and cd_id >=92;
WHERE cd_id != 90 and cd_id != 91 and cd_id != 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

14.Evaluate this SELECT statement: Mark for Review


(1) Points
SELECT last_name, first_name, salary
FROM employees;

How will the results of this query be sorted?

The results will be sorted ascending by LAST_NAME,


FIRST_NAME, and SALARY.
The results will be sorted ascending by the LAST_NAME
column only.
The database will display the rows in whatever order it finds it in
the database, so no particular order. (*)
The results will be sorted ascending by LAST_NAME and
FIRST_NAME only.

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;

In which order are the functions evaluated?

SUBSTR, CONCAT, LOWER


CONCAT, SUBSTR, LOWER (*)
LOWER, CONCAT, SUBSTR
LOWER, SUBSTR, CONCAT

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

Dates and numbers (*)


Dates and characters
Numbers and characters
None of the above

Correct
Section 5
(Answer all questions in this section)

20.Sysdate is 12-May-2004. Mark for Review


You need to store the following date: 7-Dec-89 (1) Points
Which statement about the date format for this value is true?

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 TO_CHAR(hire_date, 'ddth "of" Month YYYY')


FROM employees;

(*)
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?

SELECT companyname, TO_DATE (sysdate, 'dd, dy month,


yyyy'), total
FROM customers NATURAL JOIN orders
WHERE total >= 2500;
SELECT companyname, TO_CHAR (sysdate, 'fmdd, dy month,
yyyy'), total
FROM customers NATURAL JOIN orders
WHERE total >= 2500;
SELECT companyname, TO_DATE (date, 'day, dd month,
yyyy'), total
FROM customers NATURAL JOIN orders
WHERE total >= 2500;
SELECT companyname, TO_CHAR (sysdate, 'fmDay, dd
Month, yyyy'), total
FROM customers NATURAL JOIN orders
WHERE total >= 2500;

(*)

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

25.Which statement about group functions is true? Mark for Review


(1) Points

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?

A full outer join


A cross join (*)
An equijoin
An inner join

Correct
27.Which of the following conditions will cause an error on a Mark for Review
NATURAL JOIN? (1) Points

When the NATURAL JOIN clause is based on all columns in the


two tables that have the same name.
If the columns having the same names have different data types,
then an error is returned. (*)
If it selects rows from the two tables that have equal values in all
matched columns.
When you attempt to write it as an equijoin.

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

29.EMPLOYEES Table: Mark for Review


Name Null? Type (1) Points
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
DEPARTMENT_ID NUMBER (4)

DEPARTMENTS Table:

Name Null? Type


DEPARTMENT_ID NOT NULL NUMBER 4
DEPARTMENT_NAME NOT NULL VARCHAR2(30)
MANAGER_ID NUMBER (6)

A query is needed to display each department and its manager name


from the above tables. However, not all departments have a manager
but we want departments returned in all cases. Which of the
following SQL: 1999 syntax scripts will accomplish the task?
SELECT d.department_id, e.first_name, e.last_name
FROM employees e, departments d
WHERE e.employee_id
RIGHT OUTER JOIN d.manager_id;
SELECT d.department_id, e.first_name, e.last_name
FROM employees e
FULL OUTER JOIN departments d
ON (e.employee_id = d.manager_id);
SELECT d.department_id, e.first_name, e.last_name
FROM employees e
RIGHT OUTER JOIN departments d
ON (e.employee_id = d.manager_id);

(*)
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

32.Which SELECT statement implements a self join? Mark for Review


(1) Points
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, part 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;
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)

You issue this statement:


SELECT patient_id, doctor_id
FROM patients, doctors;

Which result will this statement provide?

A report with NO duplicate PATIENT_ID or DOCTOR_ID


values
A report containing all possible combinations of the
PATIENT_ID and DOCTOR_ID values (*)
A report containing each patient's id value and his doctor's id
value
A syntax error

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;

A listing of all unique first names in the employees table


The total number of non-null first names in the employees table
(*)
The total number of rows in the employees table
A listing of all non-null first names in the employees table

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

38.The TRUCKS table contains these columns: Mark for Review


(1) Points
TRUCKS:
TYPE VARCHAR2(30)
YEAR DATE
MODEL VARCHAR2(20)
PRICE NUMBER(10)

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;

SELECT last_name, COUNT(employee_id)


FROM EMPLOYEES
WHERE COUNT(*) > 1
GROUP BY last_name
SELECT employee_id, DISTINCT(last_name)
FROM EMPLOYEES
GROUP BY last_name
HAVING last_name > 1;
SELECT last_name, COUNT(last_name)
FROM EMPLOYEES
GROUP BY last_name
EXISTS COUNT(last_name) > 1;
SELECT last_name, COUNT(last_name)
FROM EMPLOYEES
GROUP BY last_name
HAVING COUNT(last_name) > 1;

(*)

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;

Salaries cannot be averaged as not all the numbers will divide


evenly.
The GROUP BY clause must have something to GROUP.
You cannot use a column alias in the GROUP BY clause. (*)
The department id is not listed in the departments table.

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

IN, ALL, and EVERY


IN, ANY, and ALL (*)
IN, ANY, and EQUAL
IN, ANY, and EVERY

Correct

47.Evaluate this SELECT statement: Mark for Review


(1) Points
SELECT player_id, name
FROM players
WHERE team_id IN
(SELECT team_id
FROM teams
WHERE team_id > 300 AND salary_cap > 400000);

What would happen if the inner query returned a NULL value?

No rows would be returned by the outer query. (*)


All the rows in the PLAYER table would be returned by the outer
query.
A syntax error in the outer query would be returned.
A syntax error in the inner query would be returned.

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

50.Which statement about subqueries is true? Mark for Review


(1) Points

Subqueries generally execute last, after the main or outer query


executes.
Subqueries should be enclosed in double quotation marks.
Subqueries are often used in a WHERE clause to return values for
an unknown conditional value. (*)
Subqueries cannot contain group functions.

Correct