SQL Set2 qns1
SQL Set2 qns1
a. b. c. d. e.
Consider the following SELECT statement: SELECT ename, emp_number, salary FROM employee WHERE dept_number = (SELECT dept_number FROM department WHERE location IN('CHICAGO', 'NEW YORK')) Why does this statement return an error?
a. b. c. d. A multiple-row subquery returns one row A single-row subquery returns more than one row A multiple-column subquery returns one column A multiple-row query uses a single-row subquery
2.
Consider the following SELECT statement: SELECT ename, empno, sal FROM emp WHERE deptno = (SELECT deptno FROM dept WHERE UPPER(loc) = UPPER('&loc')) When executing this statement, what could be the result?
a. b. c. d. The statement executes successfully if the LOC column in the DEPT table has unique values The statement fails if the values returned from a multiple-row subquery are compared with an equality operator in the main query The statement fails because an ampersand (&) character cannot be used in the subquery of a SELECT statement The statement executes successfully, but does not return the expected results because of the use of the UPPER function twice in the subquery
3.
Examine the following statement: 4. SELECT empno_seq.CURRVAL FROM SYS.dual; Which value is displayed?
a. b. c. d. Current value of the EMPNO_SEQ sequence Current value of the EMPNO_SEQ cursor Values of the EMPNO_SEQ column Current value of the EMPNO_SEQ index
5.
If a database is queried with the following command: SELECT object_name FROM all_objects WHERE object_type = 'TABLE';
The ITEM table contains the following columns: ID NUMBER(7) PK SALE_PRICE NUMBER(7,2) Evaluate the following SQL statements: 6. 1.SELECT MAX(sale_price), MIN(sale_price), AVG(sale_price) FROM ITEM; 2.SELECT ROUND(MAX(sale_price),2), ROUND(MIN(sale_price),2), ROUND(AVG(sale_price),2) FROM ITEM GROUP BY sale_price; How will the results differ?
a. b. c. d. Statement 2 will only display one row of results; statement 1 could display more than one One of the statements will generate an error Statement 1 will display three values; statement 2 will display three values for each sale price Statement 1 will display a result for each sale price; statement 2 will display a result for each item
Consider the following SELECT statement: SELECT dept_no "Departments", MAX(salary) "Max Salaries" FROM employee WHERE dept_no IN(200, 300, 400) GROUP BY Departments HAVING MAX(salary) > 60000; Due to which clause does this statement fail?
a. b. c. d. Group By Where Select Having
7.
8.
a. b. c. d. e.
9.
a. b. c. d.
10.
Which of the following statements regarding the use of subqueries are true?
a. b. c. d. e.
A subquery used with the IN operator must return multiple rows A subquery can be used in a CREATE VIEW statement, regardless of the number of rows it returns A subquery can be used in the SET clause of an UPDATE statement, regardless of the number of rows it returns A subquery used in an INTO clause of a SELECT statement must return only one column, but can return multiple rows A subquery CANNOT be used in the GROUP BY clause of a SELECT statement
Evaluate the following SQL*Plus command: 11. START empdetail Which task will this command accomplish?
a. b. c. d. It runs the EMPDETAIL.SQL script file It creates the EMPDETAIL.SQL file using the default file extension It executes the EMPDETAIL.SQL PL/SQL routine It invokes the editor to edit the contents of the EMPDETAIL file
Evaluate the following SELECT statement: SELECT FROM WHERE emp_id, name emp emp_id NOT IN (SELECT emp_id FROM emp WHERE dept_id = 30 AND job = 'SALESMAN');
12.
13.
a. b. c. d. e.
14.
a. b. c. d.
15.
a. b. c. d.
16.
a. b. c. d. e.
Which type of join should be written to perform an outer join of tables A and B that returns all rows from B?
Any outer join A left outer join A cross join A right outer join An inner join
17.
a. b. c. d.
How many join conditions should be there to avoid a Cartesian Join for joining three tables?
1 2 3 None of the above
18.
a. b. c. d.
Which Data Dictionary view holds information about the column in a view?
USER_VIEWS USER_VIEW_COLUMNS USER_TAB_COLUMNS USER_ALL_COLUMNS
19.
a. b. c. d. e.
Which of the following views should a user query to display the columns associated with the Constraints on a table owned by the user?
USER_CONSTRAINTS USER_OBJECTS ALL_CONSTRAINTS USER_CONS_COLUMNS USER_COLUMNS
20.
a. b. c. d. e.
Which of the following SELECT statements will get the result 'ELCOME' from the string 'WELCOME'?
SELECT SUBSTR ('WELCOME',1) FROM dual; SELECT INITCAP(TRIM('WELCOME', 1,1) FROM dual; SELECT LOWER (SUBSTR ('WELCOME', 2,1) FROM dual; SELECT LOWER (SUBSTR('WELCOME', 2,1) FROM dual; SELECT LOWER (TRIM ('W' FROM 'WELCOME')) FROM dual;
21.
a. b. c. d.
22.
a.
Evaluate the following statement: TRUNCATE TABLE product; Which of the following users can successfully issue this statement?
The owner of the INVENTORY table
b. c. d.
Any user with access to the PUBLIC schema Any user with the DELETE ANY TABLE system privilege Any member of the CONNECT and RESOURCE roles
23.
a. b. c. d.
1.
Which SQL SELECT statement performs a projection, a selection, and join when executed?
SELECT id_number,seller_id FROM ITEM ORDER BY seller_id, id_number; SELECT id_number,seller_id FROM ITEM WHERE seller_id = 'F10032'; SELECT seller_id, city FROM SALLER AND seller_id = 'F10032' ORDER BY city; SELECT p.id_number, s.seller_id, seller.city FROM ITEM p, SALLER s WHERE p.seller_id = m.seller_id AND m.seller_id='F10032';
a.
b.
c.
d.
5
a. b. c. d.
6.
a. b. c. d. e.
7.
a. b. c. d.
The names of the employees who have been with the company for more than five years is to be listed. Which of the following SQL statements will display the required results?
SELECT ENAME FROM EMP WHERE SYSDATE-HIRE_DATE>5 SELECT ENAME FROM EMP WHERE HIRE_DATE-SYSDATE > 5 SELECT ENAME FROM EMP WHERE (SYSDATE-HIRE_DATE)/365 > 5 SELECT ENAME FROM EMP WHERE (SYSDATE-HIRE_DATE)* 365 > 5
8.
EMPLOYEE -----------------EMP_ID NUMBER NOT NULL PK NAME VARCHAR(30) NOT NULL FNAME VARCHAR(25) NOT NULL DEPT_NO NUMBER TITLE VARCHAR2(25) DEPARTMENT -----------------------DEPT_ID NUMBER NOT NULL PK DEPT_NAME VARCHAR2(25) A list of departments has to be created including the department name that have more than three administrative assistants. Which SELECT statement will produce the desired result?
SELECT d.dept_name FROM employee e JOIN department d ON (e.dept_no = d.dept_id) WHERE LOWER(title) = 'administrative assistant' GROUP BY dept_name HAVING COUNT(emp_id) > 3; SELECT dept_name FROM employee e JOIN department d ON (e.dept_no = d.dept_id) WHERE LOWER(title) = 'administrative assistant' AND COUNT(*) > 3; SELECT dept_name FROM employee NATURAL JOIN department WHERE LOWER(title) = 'administrative assistant' GROUP BY dept_name HAVING COUNT(emp_id) > 3; SELECT dept_name FROM employee GROUP BY dept_no HAVING LOWER(title) = 'administrative assistant' AND COUNT(*) > 3;
a.
b.
c.
d.
The PRODUCT table contains the following columns: PRODUCT_ID NUMBER(9) DESCRIPTION VARCHAR2(20) COST NUMBER(5,2) MANUFACTURER_ID VARCHAR2(10) The product costs needs to be displayed with the following results: 1. The cost displayed for each product is increased by 20 percent. 2. The product manufacturer id must be 5001, 5020, or 5050. 3. Twenty percent of the original cost is less than $4. Which statement should be used?
SELECT description, cost * 1.20 FROM product WHERE cost * .20 < 4 AND manufacturer_id = ('5001','5020','5050'); SELECT description, cost * .20 FROM product WHERE cost * .20 < 4.00 AND manufacturer_id BETWEEN '5001' AND '5050'; SELECT description, cost * 1.20 FROM product WHERE cost * .20 < 4.00 AND manufacturer_id IN ('5001', '5020', '5050'); SELECT description, cost * 1.20 FROM product WHERE cost * .20 < 4.00 AND manufacturer_id ANY('5001', '5020', '5050');
9.
a.
b.
c.
d.
Consider the following SELECT statement: SELECT emp_id, name FROM employee WHERE emp_id NOT IN (SELECT emp_id FROM employee WHERE depart_id = 30 AND job = 'CLERK'); What would happen if the inner query returned a NULL value?
a. b. c. d. No rows would be selected from the EMPLOYEE table A syntax error would be returned All the EMP_ID and NAME values in the EMPLOYEE table would be displayed Only the rows with EMP_ID values equal to NULL would be included in the results
10.
11.
a. b. c. d.
In a SELECT statement that includes a WHERE clause, where is the GROUP BY clause placed statement?
Immediately after the SELECT clause Before the WHERE clause After the ORDER BY clause After the WHERE clause
A database was queried with the following command: SELECT name, salary, dept_id FROM employee WHERE salary > (SELECT AVG(salary) FROM employee WHERE dept_no = (SELECT dept_no FROM employee WHERE last_name = (SELECT last_name FROM employee WHERE salary > 50000))); Which SELECT clause is evaluated first?
a. b. c. d. SELECT dept_no SELECT last_name SELECT name, salary, dept_id SELECT AVG(salary)
12.
13.
a. b. c. d.
find the name of the employee from emp table whose fname second charcter begins with 'e'
select * from emp where fname like'_e%' select * from emp where fname like'e%' select * from emp where fname like'_e' select * from emp where fname like'ae%'
1.
a. b. c. d.
Which Data Dictionary view holds information about the column in a view?
USER_VIEWS USER_VIEW_COLUMNS USER_TAB_COLUMNS USER_ALL_COLUMNS
2.
a. b. c. d. e. f.
Which of the following SQL statements should be used to remove a view called EMP_DEPT_VU from the schema?
DROP emp_dept_vu; DELETE emp_dept_vu; REMOVE emp_dept_vu; DROP VIEW emp_dept_vu; DELETE VIEW emp_dept_vu; REMOVE VIEW emp_dept_vu;
3.
a. b. c. d. e.
The STUDENTS table needs to be modified to add a primary key on the STUDENT_ID column. The table is currently empty. Which of the following statements will accomplish the task?
ALTER TABLE students ADD PRIMARY KEY student_id; ALTER TABLE students ADD CONSTRAINT PRIMARY KEY (student_id); ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY student_id; ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY (student_id); ALTER TABLE students MODIFY CONSTRAINT stud_id_pk PRIMARY KEY (student_id);
Examine the structure of the EMPLOYEES and NEW_EMPLOYEES tables given below: EMPLOYEES --------------------EMPLOYEE_ID NUMBER FIRST_NAME VARCHAR2 (20) LAST_NAME VARCHAR2 (20) HIRE_DATE DATE NEW_EMPLOYEES -----------------------EMPLOYEE_ID NUMBER NAME VARCHAR2 (40)
Primary Key
4.
Primary Key
5.
a. b. c. d. e. f.
6.
a. b. c. d.
What is the syntax for removing a PRIMARY KEY constraint and all its dependent constraints?
ALTER TABLE table_name REMOVE CONSTRAINT PRIMARY KEY CASCADE; ALTER TABLE table_name DROP PRIMARY KEY CASCADE; ALTER TABLE table_name DISABLE CONSTRAINT PRIMARY KEY CASCADE; A PRIMARY KEY constraint CANNOT be removed if it has dependent constraints
7.
a. b. c. d. e.
Which statement type would be used to remove transactions more than one year old from the TRX table?
DCL DML DDL TCL DRL
8.
The PRIMARY KEY constraint was disabled on the ID column in the Product table and all the values in the Product table were updated. The constraint is to be enabled and it should be verified that the new ID column values do not violate the constraint. If any of the ID column values do not conform to the constraint, an error message should be returned. Evaluate the following statement: ALTER TABLE product ENABLE CONSTRAINT product_id_pk; Which statement is true?
a. b. c. d.
The statement will execute, but will NOT enable the PRIMARY KEY constraint The statement will achieve the desired results The statement will execute, but will NOT verify that values in the ID column do NOT violate the constraint The statement will return a syntax error
9.
A user JOE needs to be created and this user should be allowed to create and drop tables in any schema. He should be able to create procedures and sequences only in his schema. Which script should be used to achieve these results?
CREATE USER joe IDENTIFIED BY joe123; GRANT DROP ANY TABLE, CREATE SEQUENCE, CREATE PROCEDURE TO joe CREATE USER joe
a.
b.
IDENTIFIED BY joe123; GRANT CREATE TABLE, DROP TABLE, CREATE SEQUENCE, CREATE PROCEDURE TO joe CREATE USER joe IDENTIFIED BY joe123; GRANT CREATE SESSION, CREATE ANY TABLE, DROP ANY TABLE, CREATE SEQUENCE, CREATE PROCEDURE TO joe CREATE USER joe IDENTIFIED BY joe123; GRANT CREATE SESSION, DROP ANY TABLE, CREATE SEQUENCE, CREATE PROCEDURE TO joe
c.
d.
10.
a. b. c. d.
11.
The MANAGER role should be given the ability to select from insert into and modify existing rows in the STUDENT_GRADES table. Anyone given this MANAGER role should be able to pass those privileges on to others. Which statement accomplishes this?
GRANT select, insert, update ON student_grades TO manager; GRANT select, insert, update ON student_grades TO ROLE manager GRANT select, insert, modify ON student_grades TO manager WITH GRANT OPTION; GRANT select, insert, update ON student_grades TO manager WITH GRANT OPTION
a. b. c. d.
A view was created with the following command: CREATE FORCE VIEW first_vu AS SELECT first_name ||' '|| last_name "Employee Names" FROM employee ORDER BY last_name, first_name; Which clause causes an error?
a. b. c. d. CREATE FORCE VIEW first_vu ORDER BY last_name, first_name FROM employee AS SELECT first_name ||' '|| last_name "Employee Names"
12.
1.
a. b. c. d.
2.
a. b. c. d. e.
Which type of join should be written to perform an outer join of tables A and B that returns all rows from B?
Any outer join A left outer join A cross join A right outer join An inner join
3.
a. b. c. d.
How many join conditions should be there to avoid a Cartesian Join for joining three tables?
1 2 3 None of the above
4.
a. b. c. d.
Examine the code given below: 5. SELECT employee_id FROM employees WHERE commission_pct=.5 OR salary > 23000 Which of the following statement is correct with regard to this code?
a. b. c. d. It returns employees who have 50% of the salary greater than $23,000: It returns employees who have 50% commission rate or salary greater than $23,000: It returns employees who have 50% of salary less than $23,000: None of the above
6.
SEMESTER_END DATE
Which of the following statements finds the highest Grade Point Average (GPA) per semester?
a. b. c. d. e. SELECT MAX(gpa) FROM student_grades WHERE gpa IS NOT NULL; SELECT (gpa) FROM student_grades GROUP BY semester_end WHERE gpa IS NOT NULL; SELECT MAX(gpa) FROM student_grades WHERE gpa IS NOT NULL GROUP BY semester_end; SELECT MAX(gpa) GROUP BY semester_end WHERE gpa IS NOT NULL FROM student_grades; SELECT MAX(gpa) FROM student_grades GROUP BY semester_end WHERE gpa IS NOT NULL;
7.
a. b. c. d. e.
Which of the following tasks can be performed by using the TO_CHAR function?
Convert '10'to 10 Convert 10 to '10' Convert 'TEN' to 10 Convert a date to a character expression Convert a character expression to a date
8.
a. b. c. d. e.
Which of the following SELECT statements will get the result 'elloworld' from the string 'HelloWorld'?
SELECT SUBSTR ('HelloWorld',1) FROM dual; SELECT INITCAP(TRIM('HellowWorld', 1,1) FROM dual; SELECT LOWER (SUBSTR ('HellowWorld', 2,1) FROM dual; SELECT LOWER (SUBSTR('HellowWorld', 2,1) FROM dual; SELECT LOWER (TRIM ('H' FROM 'Hello World')) FROM dual;
9.
a. b. c. d.
Where is the GROUP BY clause statement placed in a SELECT statement that includes a WHERE clause?
Immediately after the SELECT clause Before the WHERE clause After the ORDER BY clause After the WHERE clause
10.
a. b. c. d.
= OR IN AND
11.
a. b. c. d.
Which type of view is implemented as a subquery embedded in the FROM clause of a SELECT statement and is identified by an alias?
Simple Inline Complex Nested
Evaluate the following SQL statement: 12. SELECT ROUND (TRUNC (MOD (1600, 10),-1), 2) FROM dual; What will be displayed?
a. b. c. d. 0 1 0.00 An error statement
n. Print the names of employees who are certified only on aircrafts with cruising range longer than 1000 miles and who are certified on some Boeing aircraft. a)select a.aname,e.ename,e.salary from aircraft a,employees e,certified c where e.eid=c.eid and c.aid=a.aid and e.salary >$80,000. b)select c.eid,max(a.cruisingrange) from certified c,aircraft a where c.aid=a.aid group by c.eid having count(*)>3; c)select e.ename from employees e where e.salary <(select f.price from flights f where f.from =' Los Angeles' and f.to = ' Honolulu'); d)select a.aname,avg(e.salary) from aircraft a,employees e, certified c where e.eid=c.eid and c.aid=a.aid and cruisingrange> 1000 group by a.aname; e)select e.ename from employees e ,certified c,aircraft a where e.eid=c.eid and c.aid=a.aid and a.aname=' Boeing aircraft'; f)select a.aid from aircraft a where a.aid in(f.flno from flights f where f.from=' Los Angeles' and f.to='chicago');
2. Consider the following relational schema. An employee can work in more than one department; the pct_time filed of the Works relation shows the percentage of time that a given employee works in a given department. Emp(eid: integer, ename: string, age: integer, salary: real) Works(eid: integer, did: integer, pct_time: integer) Dept(did: integer, dname: string, budget: real, managerid: integer) Write the following queries in SQL: a. Print the names and ages of each employee who works in both the Hardware department and the Software department. b. For each department with more than 20 full-time-equivalent employees (i.e., where the part-time and full-time employees add up to at least that many fulltime employees), print the did together with the number of employees that work in that department. c. Print the name of each employee whose salary exceeds the budget of all of the departments that he or she works in. d. Find the managerids of managers who manage only departments with budgets greater than $1 million. e. Find the enames of managers who manage the departments with the largest budgets. f. If a manager manages more than one department, he or she controls the sum of all the budgets for those departments. Find the managerids of managers who control more than $5 million. g. Find the managerids of managers who control the largest amounts. h. Find the enames of managers who manage only departments with budgets larger than $1 million, but at least one department with budget less than $5 million. a)Select e.ename,e.age from emp e,works w,dept d where e.eid=w.eid and w.did=d.did and d.dname='Hardware' and d.dname='software'; c)select e.ename from emp e where e.sal > all(select d.budget from dept d,works w where e.eid=w.eid and w.did=d.did); d)select d.managerid,d.dname from
dept d where d.budget>10,00,000; e)select e.ename from emp e where e.eid in(select d.managerid from dept d where d.budget= (select max(d1.budget) from dept1)); f)select managerid ,sum(budget)from dept group by managerid having sum(budget)>500000; h)select e.ename from emp e,dept d where e.eid=d.managerid group by e.eid having (d.budget>1,00,000 )and (d.budget<5,00,000);