SQL Practice Questions PDF
Document Details

Uploaded by SharpDivergence
Tags
Summary
This document contains a set of SQL practice questions designed to test your knowledge of SQL syntax, functions, and database querying. The questions cover topics such as SELECT statements, JOIN operations, aggregate functions, and more.
Full Transcript
1. What does the following code snippet do? Delete from customer where id = 1; Rollback; a) Performs an undo operation on the delete operation. b) Delete row from customer having id = 1 c) Both a and b d) None of the above 2. Which one is faster in terms of performance: UNION or UNION...
1. What does the following code snippet do? Delete from customer where id = 1; Rollback; a) Performs an undo operation on the delete operation. b) Delete row from customer having id = 1 c) Both a and b d) None of the above 2. Which one is faster in terms of performance: UNION or UNION ALL? a) UNION b) UNION ALL c) Both have same performance d) None 3. What will be the output for following SQL query? select * from employees where rownum = 5; a) Print record of 5th Row from employee’s table b) No rows selected c) Print record of 1st to 5th Rows from employee’s table d) SQL query error 4. Which of the following command will search for NULL values? a) IS NULL b) = NULL c) IS EMPTY d) = ‘ ‘ 5. When multiple columns are active collectively as the Primary Key, it is referred to as a) Primary Key b) Composite Key c) Alternate Key d) Surrogate Key 6. What will be the output for following Command? SELECT department_id, AVG(salary) FROM employees WHERE AVG(salary) > 8000 GROUP BY department_id; a) Display department_id and average salary having average salary more than 8000. b) Error as there should be salary in group by clause c) Error as query must use join with aggregate functions d) Error at line 3 as group function is not allowed here 7. If Select count(product_id) from order; gives 15 outputs then what will be the number of outputs for following query: Select count(distinct product_id) from order; a) 15 b) 15 d) 0 8. Which SQL keyword is used to combine the results of two or more SELECT statements? a) JOIN b) UNION c) MERGE d) COMBINE 9. Which SQL JOIN type will return all records from the left table and matching records from the right table? a) INNER JOIN b) LEFT JOIN c) RIGHT JOIN d) FULL JOIN 10. Which SQL keyword is used to retrieve data from a database table? a) GET b) EXTRACT c) FETCH d) SELECT 11. Which SQL statement is used to make permanent changes to the database? a) COMMIT b) SAVE c) PERMANENT d) ALTER 12. In SQL, which operator is used to check for matching values in a specified list? a) LIKE b) BETWEEN c) IN d) MATCH 13. Which of the following command is equivalent to given query? Select e.name, d.name from employees e join departments d on e.department_id = d.department_id; a) Select e.name, d.name from employees e natural join departments d; b) Select e.name, d.name from employees e left join departments d on e.department_id = d.department_id; c) Select e.name, d.name from employees e right join departments d on e.department_id = d.department_id; d) Select e.name, d.name from employees e full join departments d on e.department_id = d.department_id; 14. Which of the following is a single-row function? a) Concat b) min c) max d) None of the above 15. What will be the output of following function? select substr('helloworld', -1, instr('helloworld', 'l', 3, 2)) from dual; a) d b) rld c) hel d) error 16. SQL Aggregate function always return _________ values. a) Single b) multiple c) Null d) Infinite 17. We can use literal in the CONCAT function. What does literal refer to? a) Number b) Character c) Date d) All of the above 18. What is the symbol of Concatenation Operator? a) | b) || c) // d) Concat 19. Which of the following query find the total number of employees working on ‘HR’ departments? a) Select name from departments where name = ‘HR’; b) select count(*) from employees where department_id = (Select id from departments where name = ‘HR’); c) Select count(*), d.name from employees e join departments d on e.department_id = d.id; d) Select count(*), d.name from employees e join departments d on e.department_id = d.id group by d.name; 20. Which of the following query finds the total rating of the sailors who have reserved boat 103? a) SELECT SUM(s.rating) FROM sailors s, reserves r AND r.bid = 103; b) SELECT s.rating FROM sailors s, reserves r WHERE s.sid = r.sid AND r.bid = 103; c) SELECT COUNT(s.rating) FROM sailors s, reserves r WHERE s.sid = r.sid AND r.bid = 103; d) SELECT SUM(s.rating) FROM sailors s, reserves r WHERE s.sid = r.sid AND r.bid = 103;