SQL Database Quiz Questions

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Kavmuni
K
Kavmuni
Community Contributor
Quizzes Created: 1 | Total Attempts: 840
| Attempts: 840 | Questions: 35
Please wait...
Question 1 / 35
0 %
0/100
Score 0/100
1.  Operator John needs to search for text data in a column, but he only remembers part of the string. Which of the following SQL operations allows the use of wildcard comparisons (choose one)?

Explanation

The LIKE operator allows the use of wildcard comparisons in SQL. With the LIKE operator, John can search for text data in a column by using wildcard characters such as % (percent sign) to represent any number of characters or _ (underscore) to represent a single character. This allows John to search for data even if he only remembers part of the string.

Submit
Please wait...
About This Quiz
SQL Database Quiz Questions - Quiz

Welcome to practice. . . . . . . . . . .

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

Explanation

The SQL statement "SELECT DISTINCT" is used to return only different values. It eliminates duplicate rows from the result set and only displays unique values. This is useful when you want to retrieve distinct values from a column in a table.

Submit
3. With SQL, how do you select all the records from a table named "Persons" where the "LastName" is alphabetically between (and including) "Hansen" and "Pettersen"?     

Explanation

The correct answer is "SELECT * FROM Persons WHERE LastName BETWEEN 'Hansen' AND 'Pettersen'". This query will select all the records from the table "Persons" where the "LastName" is alphabetically between (and including) "Hansen" and "Pettersen".

Submit
4.  The name of the only column in the DUAL table is  

Explanation

The correct answer is DUMMY. The DUAL table is a special one-row, one-column table in Oracle database. It is often used for selecting a constant value or performing calculations. The only column in the DUAL table is named DUMMY.

Submit
5. What will be the output select INSTR('HELLOWORLD','W') from        dual; ?  

Explanation

The INSTR function in SQL is used to find the position of a substring within a string. In this case, the substring is 'W' and the string is 'HELLOWORLD'. The function will return the position of the first occurrence of the substring within the string. Since 'W' is the sixth character in 'HELLOWORLD', the output will be 6.

Submit
6. Management has asked you to calculate the value 12*salary* commission_pct for all the employees in the EMP table. The EMP table contains these columns: LAST NAME VARCNAR2(35) NOT NULL SALARY        NUMBER(9,2) NOT NULL COMMISION_PCT NUMBER(4,2) . Which statement ensures that a value is displayed in the calculated columns for all employees?  

Explanation

The correct answer is SELECT last_name, 12*salary*(nvl(commission_pct,0)) FROM emp; because the NVL function is used to substitute a null value with a specified value, in this case, 0. This ensures that even if the commission_pct column has null values, the calculation will still be performed and a value will be displayed in the calculated column for all employees.

Submit
7. Examine the data from the ORDERS and CUSTOMERS table. ORDERS ORD_ID         ORD_DATE   CUST_ID       ORD_TOTAL 100                  12-JAN-2000              15                    180000 101                  09-MAR-2000                        40                    12500 102                  09-MAR-2000                        35                    12000 103                  15-MAR-2000                        15                    6000 104                  25-JUN-2000              15                    5000 105                  18-JUL-2000               20                    7000 106                  18-JUL-2000               35                    6500 107                  21-JUL-2000               20                    8000 108                  04-AUG-2000            10   CUSTOMERS CUST_ID       CUST_NAME                                    CITY 10                                Smith Los                    Angeles 15                                Bob                             San Francisco 20                                Martin                                     Chicago 25                                Mary                            New York 30                                Rina                             Chicago 35                                Smith                           New York 40                                Linda                           New York Which SQL statement retrieves the order ID, customer ID, and order total for the orders that are placed on the same day that Martin places his orders?  

Explanation

The correct answer is the second option. This SQL statement retrieves the order ID, customer ID, and order total for the orders that are placed on the same day that Martin places his orders. It uses subqueries to first find the customer ID of Martin and then find the order dates for that customer. The main query then selects the order ID, customer ID, and order total from the orders table where the order date is in the list of order dates for Martin.

Submit
8.   The following SQL statement is illegal because: (choose one) SELECT deptno, AVG(sal) FROM emp WHERE AVG(sal)> 2000 GROUP BY deptno;

Explanation

The given SQL statement is illegal because it uses a WHERE clause to restrict groups instead of using a HAVING clause. In SQL, the WHERE clause is used to filter individual rows before they are grouped, while the HAVING clause is used to filter groups after they have been created. Since the statement is trying to restrict groups based on the average salary (AVG(sal)), it should use a HAVING clause instead of a WHERE clause.

Submit
9. ) What operator would you choose to prevent this Oracle error message? (choose one) ORA-01427:single -row subquery returns more than one row

Explanation

The ORA-01427 error message occurs when a subquery returns more than one row, which is not allowed in certain situations. To prevent this error, the IN operator can be used. The IN operator allows for multiple values to be compared against a single value, ensuring that the subquery returns only one row. By using the IN operator, the query will be able to handle cases where the subquery returns multiple rows without causing the error.

Submit
10.  ) How many columns are presented after executing this query: SELECT address1||','||address2||','||address2 "Adress" FROM employee;  

Explanation

The query is selecting three columns: address1, address2, and address2 (aliased as "Address"). The concatenation operator (||) is used to combine the values of address1, a comma, address2, a comma, and address2 again. However, since the alias "Address" is used for the third column, it appears as if there are only two distinct columns in the result. Therefore, the correct answer is 1.

Submit
11. Which query is used to find maximum of the average salary of employees?

Explanation

The correct answer is b) select max(avg(sal)) from emp group by dept_id. This query uses the MAX function to find the maximum value of the average salary of employees. It also uses the AVG function to calculate the average salary for each department by grouping the results using the GROUP BY clause.

Submit
12. How would you display a listing of the sums of employee salaries for those employees not making a commission, for each job type, including only those sums greater than 2500? (choose one)

Explanation

The correct answer is to select the job and the sum of salaries from the employee table, where the commission is null. Then, group the results by job and filter out only those sums that are greater than 2500. This query will display a listing of the sums of employee salaries for those employees not making a commission, for each job type, including only those sums greater than 2500.

Submit
13. You query the database with this command: SELECT id_number, (quantity – 100 / 0.15 – 35 * 20) FROM inventory ; Which expression is evaluated first (choose one)?

Explanation

The expression 100/0.15 is evaluated first because it is inside parentheses and according to the order of operations, expressions inside parentheses are evaluated first.

Submit
14.  What TRUNCATE and DELETE commands does?

Explanation

The TRUNCATE and DELETE commands are used to remove data from a table. However, the key difference is that TRUNCATE removes all rows from a table, while DELETE allows for selective removal of specific rows based on specified conditions. Therefore, the correct answer is "To get rid of all rows in a table."

Submit
15. With SQL, how do you select all the records from a table named "Persons" where the value of the column "FirstName" is "Peter"?   

Explanation

The correct answer is "SELECT * FROM Persons WHERE FirstName='Peter'". This query uses the SELECT statement to retrieve all columns (*) from the table "Persons" where the value of the column "FirstName" is "Peter".

Submit
16. ) Evaluate the set of SQL statements: CREATE TABLE      dept     (deptno NUMBER(2), dname VARCNAR2(14), loc VARCNAR2(13)); ROLLBACK; DESCRIBE DEPT What is true about the set?  

Explanation

The DESCRIBE DEPT statement is used to display the structure of the DEPT table. It provides information about the columns and their data types in the table.

Submit
17. Examine the description of the EMPLOYEES table: EMP_ID NUMBER(4) NOT NULL LAST_NAME VARCHAR2(30) NOT NULL FIRST_NAME VARCHAR2(30) DEPT_ID NUMBER(2) JOB_CAT VARCHARD2(30) SALARY NUMBER(8,2)   Which statement shows the maximum salary paid in each job category of each department?  

Explanation

The correct answer is "SELECT dept_id, job_cat, MAX(salary) FROM employees GROUP BY dept_id, job_cat;". This statement uses the GROUP BY clause to group the data by department and job category. Then, it uses the MAX() function to find the maximum salary within each group. This will give the maximum salary paid in each job category of each department.

Submit
18. Which of the following queries would show the salaries of all employees (not the boss) who have the same name as the boss (the only employee without a manager (mgr)) (choose one)? 

Explanation

The correct answer is the second option: select sal from emp where ename like (select ename from emp where mgr is NULL) and mgr is not NULL. This query selects the salaries from the emp table where the employee name is the same as the boss (the only employee without a manager) and the manager is not NULL. This ensures that only employees who have the same name as the boss and are not the boss themselves are included in the result.

Submit
19. The EMPLOYEE tables has these columns: LAST_NAME VARCHAR2(35) SALARY NUMBER(8,2) COMMISSION_PCT NUMBER(5,2) You want to display the name and annual salary multiplied by the commission_pct for all employees. For records that have a NULL commission_pct, a zero must be displayed against the calculated column. Which SQL statement displays the desired results?  

Explanation

The correct answer is "SELECT last_name, (salary * 12) * NVL(commission_pct, 0) FROM EMPLOYEES;". This statement uses the NVL function to replace NULL values in the commission_pct column with 0. It then multiplies the annual salary (salary * 12) by the commission_pct to calculate the desired result.

Submit
20. Which Oracle access method is the fastest way for Oracle to retrieve a single row?

Explanation

Table access by ROWID is the fastest way for Oracle to retrieve a single row because it directly accesses the row using the unique identifier known as ROWID. This method does not require any additional lookups or index scans, making it the most efficient way to retrieve a specific row from a table. Primary key access and access via unique index also involve index lookups, while a full table scan reads all the rows in the table, making them slower compared to table access by ROWID.

Submit
21. All of the following can ONLY be used with numeric datatypes except: (choose one) 

Explanation

COUNT is the only function among the options that can be used with both numeric and non-numeric datatypes. It counts the number of rows in a table or the number of occurrences of a specific value. AVG, SUM, STDDEV, and VARIANCE are all functions that specifically operate on numeric datatypes and perform mathematical calculations.

Submit
22. Which of the following query  display the last name,hire date and the day of the week on which the employee started with column label as DAY and ordered by the day of the week starting with Monday.

Explanation

The correct answer is the first option: SELECT last_name, hire_date, TO_CHAR(hire_date,'DAY') AS DAY
FROM employees
ORDER BY hire_date, DAY;

This query selects the last name, hire date, and the day of the week on which the employee started. The TO_CHAR function is used to convert the hire date to the day of the week format. The column label for the day of the week is set as "DAY". The result is ordered by the hire date and the day of the week, starting with Monday.

Submit
23. Which clause should you use to exclude GROUP results ?  

Explanation

The HAVING clause is used to exclude GROUP results in a SQL query. It is typically used in combination with the GROUP BY clause to filter the results based on conditions that are applied to the grouped data. This allows you to specify criteria for the groups that should be included or excluded in the final result set. The HAVING clause is different from the WHERE clause, which is used to filter individual rows before they are grouped.

Submit
24. Substitution variable can be used with which of the following clauses?

Explanation

Substitution variables can be used with all of the mentioned clauses (Select, From, Where, Group by). Substitution variables are placeholders that can be used to dynamically substitute values in a SQL statement. They are commonly used to make the SQL statement more flexible and reusable by allowing users to input different values at runtime. By using substitution variables, the same SQL statement can be executed with different values without the need to modify the statement itself.

Submit
25. What output will the follwing statement produce? Select NVL2(NULL,'NOT NULL', NULL) from dual;  

Explanation

The NVL2 function in Oracle is used to determine the value to be returned based on the condition. In this case, the condition is NULL. If the condition is true, the second argument ('NOT NULL') is returned. If the condition is false or NULL, the third argument (NULL) is returned. Since the condition is NULL, the third argument is returned, resulting in the output of NULL.

Submit
26. What will be the output ? SELECT ROUND(TRUNC(MOD(1600,10),-1),2) from dual;  

Explanation

The given SQL statement calculates the modulus of 1600 divided by 10, which results in 0. The TRUNC function is then used to truncate this value to the nearest multiple of 10, which is also 0. Finally, the ROUND function is applied to round this value to 2 decimal places, which is still 0. Therefore, the output of the statement will be 0.

Submit
27. Which of the following statements are true (choose two)?

Explanation

'NOT IN' is equivalent to != ALL means that when using the 'NOT IN' operator, it checks if a value is not present in a set of values, similar to using the != (not equal to) operator with the ALL keyword.

'IN' is equivalent to =ANY means that when using the 'IN' operator, it checks if a value is present in a set of values, similar to using the = (equal to) operator with the ANY keyword.

Both statements explain the equivalence between these operators and their corresponding combinations with the != and = operators.

Submit
28. Which of the following can be a valid column name? 

Explanation

column name should start with a alphabet and it cannot start with no: or special char

Submit
29. Which SELECT statement will return a numeric value?

Explanation

The SELECT statement that will return a numeric value is the fourth option: SELECT (SYSDATE - enroll_date) + 30.5 * 9 FROM student. This is because it performs mathematical operations (subtraction, multiplication, and addition) on the values SYSDATE, enroll_date, and 30.5, which are all numeric values. The result of these operations will also be a numeric value.

Submit
30.  ) Assuming today is Monday, 10 July 2000, what is returned by this statement: SELECT to_char(NEXT_DAY(sysdate, 'MONDAY'), 'DD-MON-RR') FROM dual;  

Explanation

The statement returns the date of the next Monday from the current date. Since today is Monday, 10 July 2000, the next Monday after this date is 17 July 2000. Therefore, the statement will return "17-JUL-00".

Submit
31. Examine the description of the STUDENTS table: STD_ID          NUMBER(4) COURSE_ID             VARCHARD2(10) START_DATE DATE END_DATE   DATE Which two aggregate functions are valid on the START_DATE column? (Choose two)  

Explanation

The COUNT(start_date) function is valid on the START_DATE column because it counts the number of non-null values in the column. The MIN(start_date) function is also valid on the START_DATE column because it returns the minimum value in the column.

Submit
32.  SELECT ROUND (45.953, -1), TRUNC (45.936, 2) FROM dual; Which values are displayed?  

Explanation

The ROUND function rounds the first number, 45.953, to the nearest multiple of 10, resulting in 50. The TRUNC function truncates the second number, 45.936, to two decimal places, resulting in 45.93. Therefore, the values displayed are 50 and 45.93.

Submit
33. Given the following data in the emp table: ENAME SALARY -------- -------- PING 5000 AILYN 4999 SAM 1000 LESLIE 3000 TOM 2500 RAVI 10000 What will the following select statement produce (choose one)? SELECT ename FROM emp WHERE salary BETWEEN 3000 AND 5000;

Explanation

The select statement will produce the following result: ENAME
--------
AILYN
CHRIS
LESLIE
This is because the select statement is filtering the data from the emp table based on the condition WHERE salary BETWEEN 3000 AND 5000, which means it will select all the rows where the salary is between 3000 and 5000, inclusive. In this case, the rows with the names AILYN, CHRIS, and LESLIE have salaries within this range, so they will be included in the result. Therefore, the correct answer is "None of the above" as it is not one of the given options.

Submit
34. Examine the structure of the employees table. Employee_id number primary key First_name varchar2(25) Last_name varchar2(25) Which 3 statements inserts a row into the table employees?  

Explanation

The correct answers are C, E, and F.

C. INSERT INTO employees VALUES(1000,’John’’Smith’); - This statement inserts a row into the employees table with the specified values for employee_id, first_name, and last_name.

E. INSERT INTO employees (employee_id) VALUES(1000); - This statement inserts a row into the employees table with only the employee_id specified.

F. INSERT INTO employees (employee_id,first_name,last_name) VALUES(1000’John’,’’); - This statement inserts a row into the employees table with the specified values for employee_id, first_name, and last_name. However, there is a syntax error in the statement as there is a missing comma between 1000 and 'John'.

Submit
35. Which of the following are legal queries? (choose one or more)

Explanation

The correct answer includes two queries: "SELECT deptno, avg(sal) FROM emp GROUP BY deptno;" and "SELECT avg(sal) FROM emp GROUP BY deptno;". These queries are legal because they both use the "avg" function to calculate the average salary and group the results by the department number. This is a valid use of the "GROUP BY" clause in SQL.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 22, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Dec 01, 2011
    Quiz Created by
    Kavmuni
Cancel
  • All
    All (35)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
 Operator John needs to search for text data in a column, but he...
Which SQL statement is used to return only different values?  
With SQL, how do you select all the records from a table named...
 The name of the only column in the DUAL table is  
What will be the output select INSTR('HELLOWORLD','W')...
Management has asked you to calculate the value 12*salary*...
Examine the data from the ORDERS and CUSTOMERS table....
 ...
) What operator would you choose to prevent this Oracle error message?...
 ) How many columns are presented after executing this query:...
Which query is used to find maximum of the average salary of...
How would you display a listing of the sums of employee salaries for...
You query the database with this command: ...
 What TRUNCATE and DELETE commands does?
With SQL, how do you select all the records from a table named...
) Evaluate the set of SQL statements:...
Examine the description of the EMPLOYEES table:...
Which of the following queries would show the salaries of all...
The EMPLOYEE tables has these columns:...
Which Oracle access method is the fastest way for Oracle to retrieve a...
All of the following can ONLY be used with numeric datatypes except:...
Which of the following query  display the last name,hire date...
Which clause should you use to exclude GROUP results ?  
Substitution variable can be used with which of the following clauses?
What output will the follwing statement produce? ...
What will be the output ? ...
Which of the following statements are true (choose two)?
Which of the following can be a valid column name? 
Which SELECT statement will return a numeric value?
 ) Assuming today is Monday, 10 July 2000, what is returned by...
Examine the description of the STUDENTS table:...
 SELECT ROUND (45.953, -1), TRUNC (45.936, 2) FROM dual; ...
Given the following data in the emp table: ...
Examine the structure of the employees table....
Which of the following are legal queries? (choose one or more)
Alert!

Advertisement