0% found this document useful (0 votes)
35 views5 pages

Test SQL: - Part 1 SQL/ DWH Basis

The document contains a test on SQL concepts with 20 multiple choice questions. It covers topics like data warehouse characteristics, SQL clauses like WHERE, HAVING, UNION, JOINs, aggregation, DML statements, and data types. Sample table structures and queries are provided to demonstrate concepts like joins, aggregation, filtering etc.

Uploaded by

Cont Lol
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
35 views5 pages

Test SQL: - Part 1 SQL/ DWH Basis

The document contains a test on SQL concepts with 20 multiple choice questions. It covers topics like data warehouse characteristics, SQL clauses like WHERE, HAVING, UNION, JOINs, aggregation, DML statements, and data types. Sample table structures and queries are provided to demonstrate concepts like joins, aggregation, filtering etc.

Uploaded by

Cont Lol
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 5

TEST SQL

-Part 1 SQL/ DWH basis-

1. Mention 3 characteristics of a data warehouse that distinguish it from an operational system

2. What is the difference between the WHERE and HAVING clauses?

3. What is the difference between UNION and UNION ALL?

4. Find the SQL statement below that is equal to the following: SELECT name FROM customer WHERE state = 'VA';
A.SELECT name IN customer WHERE state IN ('VA');
B.SELECT name IN customer WHERE state = 'VA';
C.SELECT name IN customer WHERE state = 'V';
D.SELECT name FROM customer WHERE state IN ('VA');

5. Which SQL statement is used to extract data from a database?


A) GET
B) OPEN
C) EXTRACT
D) SELECT

6. With SQL, how do you select a column named "FirstName" from a table named "Persons"?

A) SELECT FirstName FROM Persons


B) EXTRACT FirstName FROM Persons
C) SELECT Persons.FirstName

7. With SQL, how do you select all the columns from a table named "Persons"?
A) SELECT * FROM Persons
B) SELECT Persons
C) SELECT *.Persons
D) SELECT [all] FROM Persons

8. Which SQL statement is used to return only different values?


A) SELECT DIFFERENT
B) SELECT UNIQUE
C) SELECT DISTINCT

9. Which statement/command would cause a transaction to end?


A) COMMIT
B) SAVEPOINT
C) BACK_CHUNK
D) ROLLED

10. Can you join a table to itself?


A) No
B) Yes

11. What is the purpose of the SQL AS clause?


A) The AS SQL clause is used change the name of a column in the result set or to assign a name to a derived column.
B) The AS clause defines a search condition.
C) The AS clause is used with the JOIN clause only.

12. What does the following SQL statement do: SELECT Customer, COUNT (Order) FROM Sales GROUP BY Customer HAVING COUNT(Order) >5
A) Selects all Customers from the Sales table
B) Selects all customers from table Sales that have made more than 5 orders.
C) Selects the total number of orders from the Sales table, if this number is greater than 5

13. Which INSERT statement is valid?


A) INSERT INTO employees (employee_id, first_name, last_name, hire_date) VALUES ( 1000, ‘John’, ‘Smith’, ‘01/01/01’);
B) INSERT INTO employees(employee_id, first_name, last_name, hire_date) VALUES ( 1000, ‘John’, ‘Smith’, ’01 January 01’);
C) INSERT INTO employees(employee_id, first_name, last_name, Hire_date) VALUES ( 1000, ‘John’, ‘Smith’, To_date(‘01/01/01’));
D) INSERT INTO employees(employee_id, first_name, last_name, hire_date) VALUES ( 1000, ‘John’, ‘Smith’, 01-Jan-01);

14. You issue the following command to drop the PRODUCTS table: SQL>DROP TABLE products; What is the implication of this command? (Choose
all that apply.)
A) All data in the table are deleted but the table structure will remain
B) All data along with the table structure is deleted
C) All views and synonyms will not remain but they are invalidated
D) All indexes on the table will remain but they are invalidated

15. Where can sub queries be used?


A) the HAVING clause in the SELECT statement
B) the GROUP BY clause in the SELECT statement
C) the WHERE clause in only the SELECT statement
D) the WHERE clause in SELECT as well as all DML statements

16. Which one is true?


A) A MERGE statement is used to merge the data of one table with data from another.
B) A MERGE statement replaces the data of one table with that of another.
C) A MERGE statement can be used to revert new rows into a table
D) A MERGE statement can be used to update all rows in a table.

17.Evaluate the following SQL statement: DELETE FROM sales;


A) It removes all the rows as well as the structure of the table
B) It removes all the rows in the table and deleted rows cannot be rolled back
C) It removes all the rows in the table and deleted rows can be rolled back
D) It would not remove the rows if the table has a primary key

18. Examine the structure of the EMPLOYEES table: Which UPDATE statement is valid?
A) UPDATE employees SET first_name = ‘John’ SET last_name = ‘Smith’ WHERE employee_id = 180;
B) UPDATE employees SET first_name = ‘John’, SET last_name = ‘Smoth’ WHERE employee_id = 180;
C) UPDATE employee SET first_name = ‘John’ AND last_name = ‘Smith’ WHERE employee_id = 180;
D) UPDATE employee SET first_name = ‘John’, last_name = ‘Smith’ WHERE employee_id = 180;

19. Evaluate the SQL statement: TRUNCATE TABLE DEPT; Which one is true about the SQL statement?
A) It releases the storage space used by the table
B) You can roll back the deletion of rows after the statement executes.
C) You can NOT roll back the deletion of rows after the statement executes.
D) An attempt to use DESCRIBE on the DEPT table after the TRUNCATE statement executes will display an error.

20. For which action, can you use the TO_DATE function?
A) Convert any date literal to a date
B) Convert any numeric literal to a date
C) Convert any character literal to a date
D) Convert any date to a character literal

-Part 2 SQL test-

1. View the Exhibit and examine the structure of the EMP and SALGRADE tables. You want to display the names of all employees whose
salaries belong to GRADE 5. Which SQL statements give the required output? (Choose all that apply)

A.SELECT ename
FROM emp JOIN salgrade
USING (sal BETWEEN losal AND hisal) AND grade = 5;
B.SELECT ename
FROM emp e JOIN salgrade s
ON (e.sal BETWEEN s.losal AND s.hisal AND s.grade = 5);
C. SELECT ename 
FROM emp e JOIN salgrade s 
ON (e.sal BETWEEN s.losal AND s.hisal) AND s.grade = 5;
D. SELECT ename 
FROM emp e JOIN salgrade s 
ON (e.sal BETWEEN s.losal AND s.hisal) WHERE s.grade=5;
E.SELECT ename 
FROM emp e JOIN salgrade s 
WHERE e.sal BETWEEN s.losal AND s.hisal AND s.grade = 5;

1a "Exhibit" 

EMP          

Name Null? Type


     
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
 
HIREDATE DATE
SAL NUMBER(7,2)  
DEPTNO NUMBER(2)

SALGRADE    
Name Null? Type
     
GRADE NUMBER
LOSAL   NUMBER
HISAL NUMBER

2. View the Exhibit and examine the structure of the DEPARTMENTS and LOCATIONS tables. You want to display all the cities and the
corresponding departments in them, if any. Which query would give you the required output? 
A.SELECT location_id LOC, city, department_id DEPT
FROM locations LEFT OUTER JOIN departments 
USING (location_id);
B.SELECT location_id LOC, city, department_id DEPT 
FROM locations RIGHT OUTER JOIN departments 
USING (location_id);
C. SELECT l.location_id LOC, l.city, d.department_id DEPT 
FROM locations l LEFT OUTER JOIN departments d 
USING (location_id);
D. SELECT l.location_id LOC, l.city, d.department_id DEPT 
FROM locations l FULL OUTER JOIN departments d 
USING (location_id);

2a "Exhibit" 

DEPARTMENTS      

Name Null? Type


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

  LOCATIONS    
 

Name Null? Type


     
LOCATION_ID NOT NULL NUMBER(4)
STREET_ADDRESS VARCHAR2(40) 
POSTAL_CODE VARCHAR2(12) 
CITY NOT NULL VARCHAR2(30)
STATE_PROVINCE VARCHAR2(25) 
COUNTRY_ID CHAR(2)

3. View the Exhibit and examine the structure of the EMPLOYEES and DEPARTMENTS tables. You want to display the last names and
hire dates of all latest hires in their respective departments in the location ID 1700. You issue the following query:

SQL>SELECT last_name, hire_date 


FROM employees 
WHERE (department_id, hire_date) IN
(SELECT department_id, MAX(hire_date)
FROM employees JOIN departments 
USING(department_id) 
WHERE location_id = 1700
GROUP BY department_id);

What is the outcome? 


A.It executes but does not give the correct result
B.It executes successfully and gives the correct result
C. It generates an error because of the pairwise comparison
D. It generates an error because the GROUP BY clause cannot be used with table joins in a subquery

3a "Exhibit" 
 
EMPLOYEES      

Name Null? Type  


     
EMPLOYEE_ID NOT NULL  NUMBER(6)
FIRST_NAME VARCHAR2(20) 
LAST_NAME NOT NULL  VARCHAR2(25) 
HIRE_DATE NOT NULL  DATE
JOB_ID NOT NULL VARCHAR2(10) 
SALARY NUMBER(8, 2)
DEPARTMENT_ID NUMBER(4)
DEPARTMENTS    

Name Null? Type


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

4. View the Exhibit and examine the structure of the LOCATIONS and DEPARTMENTS tables. You need to display all those cities that
have only one department. Which query gives the correct output? 
A.SELECT location_id, city
FROM locations l 
WHERE 1 = (SELECT COUNT(*) 
FROM departments
WHERE location_id = l.location_id);
B.SELECT location_id, city
FROM locations WHERE EXISTS (SELECT COUNT(*)
FROM departments
GROUP BY location_id HAVING COUNT(*) = 1);
C. SELECT location_id, city 
FROM locations WHERE 
1 = (SELECT COUNT(*) FROM departments 
GROUP BY location_id);
D. SELECT l.location_id, city 
FROM locations l JOIN departments d ON (l.location_id = d.location_id) 
WHERE EXISTS (SELECT COUNT(*) 
FROM departments d 
WHERE l.location_id =d.location_id);

4a "Exhibit" 

LOCATIONS      

Name Null? Type


     
LOCATION_ID NOT NULL NUMBER(4)
STREET_ADDRESS VARCHAR2(40) 
POSTAL_CODE VARCHAR2(12) 
CITY VARCHAR2(30)
STATE_PROVINCE VARCHAR2(25) 
  COUNTRY_ID CHAR(2)

 
DEPARTMENTS    

Name Null? Type


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

5. View the Exhibit and examine the structure of the EMP table. You want to display the names and salaries of only those employees who
earn the highest salaries in their departments. Which two SQL statements give the required output? (Choose two.)
A.SELECT ename, sal 
FROM emp e 
WHERE sal = (SELECT MAX(sal) 
FROM emp 
WHERE deptno = e.deptno);
B.SELECT ename, sal 
FROM emp 
WHERE sal = ALL (SELECT MAX(sal) 
FROM emp 
GROUP BY deptno);
C. SELECT ename, sal 
FROM emp e 
WHERE EXISTS (SELECT MAX(sal) 
FROM emp WHERE deptno = e.deptno);
D. SELECT ename, sal 
FROM emp 
NATURAL JOIN (SELECT deptno, MAX(sal) sal 
FROM emp 
GROUP BY deptno) ;

You might also like