wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

SQL & JDBC Test

Total questions: 39

Worksheet time: 59mins

Name
Class
Date
1.
Full Name
4 lines
2.
What does SQL stand for?
a)

Standard Query Language

b)

Structured Query Language

c)

Both

d)

None

3.
Which of the following is used to retrieve data from a SQL database?
a)
INSERT
b)
UPDATE
c)
DELETE
d)
SELECT
4.
Which of the following is a join that returns only the rows that have matching values in both tables?
a)
LEFT JOIN
b)
RIGHT JOIN
c)
FULL OUTER JOIN
d)
INNER JOIN
5.
Which of the following is a join that returns all the rows from the left table and matching rows from the right table?
a)
LEFT JOIN
b)
RIGHT JOIN
c)
FULL OUTER JOIN
d)
INNER JOIN
6.
Which of the following is used to calculate the average value of a numeric column in SQL?
a)
COUNT
b)
MAX
c)
MIN
d)
AVG
7.
Which of the following is used to add new rows to a SQL table?
a)
INSERT
b)
UPDATE
c)
DELETE
d)
SELECT
8.
What is JDBC?
a)
A programming language
b)
A Java API for connecting and executing SQL statements on a database
c)
A type of database system
d)
A type of web browser
9.
Which of the following is used to establish a connection to a database using JDBC?
a)
Connection.createStatement()
b)
DriverManager.getConnection()
c)
Connection.prepareStatement()
d)
Statement.executeQuery()
10.
Which SQL keyword is used to retrieve only distinct records from a table?
a)
DISTINCT
b)
UNIQUE
c)
SELECT DISTINCT
d)
DISTINCTROW
11.
Which of the following is not a type of join in SQL?
a)
Inner join
b)
Cross join
c)
Left join
d)
Right join
12.
Which of the following is not a function in SQL?
a)
COUNT
b)
SUM
c)
AVG
d)
ADD
13.
Which of the following is used to retrieve data from more than one table in a single SQL query?
a)
Join
b)
Subquery
c)
Union
d)
All of the above
14.
Which SQL keyword is used to sort the result-set in ascending or descending order?
a)

ORDER BY

b)

SORT BY

c)

GROUP BY

d)

None

15.

Which of the following is a method to run SQL queries using JDBC?

a)

PreparedStatement

b)

CallableStatement

c)

Statement

d)

All of the above

16.
Which method of the ResultSet interface is used to move the cursor forward one row at a time?
a)
previous()
b)
first()
c)
absolute()
d)
next()
17.
Which of the following statements is used to rename a table in MySQL?
a)

ALTER TABLE

b)

RENAME TABLE

c)

Both

d)

None

18.
Which of the following is NOT a valid SQL aggregate function in MySQL?
a)
COUNT
b)
MAX
c)
AVG
d)
MATH
e)
SUM
19.
Which of the following SQL statements is used to insert new data into a MySQL table?
a)
UPDATE
b)
INSERT
c)
SELECT
d)
DELETE
20.
Which of the following is the correct syntax to create a new database in MySQL?
a)

CREATE DATABASE database_name;

b)

CREATE SCHEMA database_name;

c)

NEW DATABASE database_name;

d)

None of the above

21.
Which of the following SQL statements is used to delete a table in MySQL?
a)

TRUNCATE TABLE

b)

DELETE TABLE

c)

DROP TABLE

d)

All of the above

22.
Which of the following SQL JOINs returns all rows from both tables, regardless of whether there is a match in the other table or not?
a)
INNER JOIN
b)
LEFT JOIN
c)
RIGHT JOIN
d)
FULL OUTER JOIN
23.
What is the purpose of the HAVING clause in a SQL query?
a)
It filters the data based on a specified condition
b)
It sorts the data in ascending order
c)
It sorts the data in descending order
d)
It filters the results of a GROUP BY clause based on a specified condition
24.
Full Name
4 lines
25.
Given the following query, what will be the result? SELECT empno, ename, sal FROM emp WHERE sal > 3000 ORDER BY sal DESC;
a)
Returns the employee number, name, and salary of all employees in the emp table.
b)
Returns the employee number, name, and salary of all employees with a salary less than or equal to 3000.
c)
Returns the employee number, name, and salary of all employees with a salary greater than 3000, sorted by salary in descending order.
d)
Returns the employee number, name, and salary of all employees with a salary greater than or equal to 3000.
26.
Given the following query, what will be the result? SELECT COUNT(DISTINCT deptno) FROM emp;
a)
Returns the number of departments in the emp table.
b)
Returns the number of distinct department numbers in the emp table.
c)
Returns the number of employees in each department.
d)
Returns the number of distinct employee names in the emp table.
27.
Given the following query, what will be the result? SELECT ename, sal FROM emp WHERE deptno = 10 AND sal > 2000;
a)
Returns the employee name and salary for all employees in department 10 with a salary greater than or equal to 2000
b)
Returns the employee name and salary for all employees in department 20 with a salary greater than 2000.
c)
Returns the employee name and salary for all employees in department 10 with a salary less than or equal to 2000.
d)
Returns the employee name and salary for all employees in department 10 with a salary greater than 2000.
28.
Given the following query, what will be the result? SELECT AVG(sal) FROM emp WHERE deptno = 20;
a)

Returns the average salary for all employees in department 10.

b)

Returns the average salary for all employees in department 20.

c)

Returns the sum of salaries for all employees in department 20.

d)

Returns the average salary for all employees in department 20, rounded to the nearest whole number.

29.
Given the following query, what will be the result? SELECT ename, sal, job FROM emp WHERE job LIKE '%MAN%';
a)
Returns the employee name, salary, and job title for all employees whose job title contains the word "MAN".
b)
Returns the employee name, salary, and job title for all employees whose job title contains the string "MAN".
c)
Returns the employee name, salary, and job title for all employees whose job title starts with the letters "MAN".
d)
Returns the employee name, salary, and job title for all employees whose job title ends with the
30.
Given the following query, what is the result? SELECT COUNT(*) FROM employees WHERE salary > 50000;
a)
Total number of employees
b)
Employees with salary > 50000
c)
Total salary of employees with salary > 50000
d)
Total number of employees with salary > 50000
31.
Given the following query, what is the result? SELECT MAX(salary) FROM employees WHERE department_id = 10;
a)
Maximum salary of employees
b)
Maximum salary of employees in department 10
c)
Maximum salary of employees in department 10 only
32.
Given the following query, what is the result? SELECT AVG(salary) FROM employees WHERE department_id IN (20, 30);
a)
Average salary of employees
b)
Average salary of employees in departments 20 and 30
c)
Average salary of employees not in departments 20 and 30
33.
Given the following query, what is the result? SELECT department_id, COUNT(*) FROM employees GROUP BY department_id;
a)
Total number of employees in each department
b)
Total number of employees in each department_id
c)
Total number of departments with employees
d)
Total number of employees
34.
Given the following query, what is the result? SELECT salary, COUNT() FROM employees GROUP BY salary HAVING COUNT() > 1;
a)
List of salaries with more than one employee
b)
List of salaries with more than one employee and the count of employees with that salary
c)
List of employees with more than one salary
35.
Given the following query, what is the result? SELECT first_name, last_name FROM employees WHERE last_name LIKE '%son';
a)
List of employees with last name ending in 'son'
b)
List of employees with last name containing 'son'
c)
List of employees with last name starting with 'son'
36.
Given the following query, what is the result? SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM employees;
a)
List of employees' full names
b)
List of employees' first names
c)
List of employees' last names
37.
Given the following query, what is the result? SELECT department_id, AVG(salary) FROM employees WHERE job_id LIKE 'SA%' GROUP BY department_id;
a)
Average salary of employees with job_id starting with 'SA'
b)
Average salary of employees in departments with job_id starting with 'SA'
c)
Average salary of employees with job_id starting with 'SA' in each department
38.
Given the following query, what is the result? SELECT first_name, last_name FROM employees ORDER BY last_name DESC, first_name ASC;
a)
List of employees sorted by first name ascending and last name descending
b)
List of employees sorted by last name descending and first name ascending
c)
List of employees sorted by first name descending and last name ascending
39.
Given the following query, what is the result? SELECT department_name, MAX(salary) FROM employees JOIN departments ON employees.department_id = departments.department_id GROUP BY department_name;
a)
Maximum salary of employees in each department
b)
Maximum salary of employees in each department with department name
c)
List of employees with maximum salary in each department