wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

SQL

Total questions: 45

Worksheet time: 22mins

Name
Class
Date
1.

Which SQL function is used to count the number of rows in a SQL query?

a)

COUNT()

b)

NUMBER()

c)

SUM()

d)

COUNT(*)

2.

If you don’t specify ASC or DESC after a SQL ORDER BY clause, the following is used by default

a)

ASC

b)

DESC

c)

There is no default value

d)

None of the mentioned

3.

With SQL, how do you select all the records from a table named “Persons” where the value of the column “FirstName” ends with an “a”?

a)

SELECT * FROM Persons WHERE FirstName=’a’

b)

SELECT * FROM Persons WHERE FirstName LIKE ‘a%’

c)

SELECT * FROM Persons WHERE FirstName LIKE ‘%a’

d)

SELECT * FROM Persons WHERE FirstName=’%a%’

4.

What does the ALTER TABLE clause do?

a)

The SQL ALTER TABLE clause modifies a table definition by altering, adding, or deleting table columns and/or constraints

b)

The SQL ALTER TABLE clause is used to insert data into database table

c)

THE SQL ALTER TABLE deletes data from database table

d)

The SQL ALTER TABLE clause is used to delete a database table

5.

The UPDATE SQL clause can _____________

a)

update only one row at a time

b)

update more than one row at a time

c)

delete more than one row at a time

d)

delete only one row at a time

6.

How can you change “Hansen” into “Nilsen” in the “LastName” column in the Persons table?

a)

UPDATE Persons SET LastName=’Hansen’ INTO LastName=’Nilsen’

b)

MODIFY Persons SET LastName=’Nilsen’ WHERE LastName=’Hansen’

c)

MODIFY Persons SET LastName=’Hansen’ INTO LastName=’Nilsen’

d)

UPDATE Persons SET LastName=’Nilsen’ WHERE LastName=’Hansen’

7.

SQL query to find all the cities whose humidity is 95.

a)

SELECT city WHERE humidity = 95

b)

SELECT city FROM weather WHERE humidity = 95

c)

SELECT humidity = 89 FROM weather

d)

SELECT city FROM weather

8.

SQL query to find the temperature in increasing order of all cities.

a)

SELECT city FROM weather ORDER BY temperature

b)

SELECT city, temperature FROM weather

c)

SELECT city, temperature FROM weather ORDER BY temperature

d)

SELECT city, temperature FROM weather ORDER BY city

9.

Find the name of those cities with temperature and condition whose condition is either sunny or cloudy but temperature must be greater than 70.

a)

SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ AND condition = ‘cloudy’ OR temperature > 70

b)

SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ OR condition = ‘cloudy’ OR temperature > 70

c)

SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ OR condition = ‘cloudy’ AND temperature > 70

d)

SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ AND condition = ‘cloudy’ AND temperature > 70

10.

The command to remove rows from a table ‘CUSTOMER’ is __________________

a)

DROP FROM CUSTOMER

b)

UPDATE FROM CUSTOMER

c)

REMOVE FROM CUSTOMER

d)

DELETE FROM CUSTOMER WHERE

11.

Find the names of these cities with temperature and condition whose condition is neither sunny nor cloudy.

a)

SELECT city, temperature, condition FROM weather WHERE condition NOT IN (‘sunny’, ‘cloudy’)

b)

SELECT city, temperature, condition FROM weather WHERE condition NOT BETWEEN (‘sunny’, ‘cloudy’)

c)

SELECT city, temperature, condition FROM weather WHERE condition IN (‘sunny’, ‘cloudy’)

d)

SELECT city, temperature, condition FROM weather WHERE condition BETWEEN (‘sunny’, ‘cloudy’);

12.

If you were wanting to filter data, which clause would you use?

a)

Where

b)

Order by

c)

From

d)

Select

13.

Which statement allows us to add a record to a table?

a)

Add To

b)

Update To

c)

Add Into

d)

Insert Into

14.

Less than or equal to?

a)

>=

b)

=>

c)

=<

d)

<=

15.

Which character returns all the data found in a table?

a)

%

b)

#

c)

*

d)

/

16.

You are required to update the phone number for only the DesignerID "SMI01" in the "Designer" table. Which of these would successfully do that?

a)

UPDATE Designer SET PhoneNo = '01224123456'

b)

UPDATE Designer (PhoneNo) VALUES ('01224123456')

c)

UPDATE Designer SET PhoneNo = '01224123456' WHERE DesignerID = 'SMI01'

d)

UPDATE PhoneNo = '01224123456' FROM Designer WHERE DesignerID = 'SMI01'

17.

Which of the following is not a database data type?

a)

text

b)

number

c)

array

d)

date

18.

Referential Integrity is

a)

System of rules

b)

System of data

c)

Table constraints

d)

is related to Primary key

19.

______________ constraint prevents NULL values

a)

UNIQUE

b)

NOT NULL

c)

NULL

d)

FOREIGN KEY

20.

A primary key can be NULL in the table? TRUE or FALSE

a)

TRUE

b)

FALSE

21.

What would the SQL query pictured do?

a)

Find all the men

b)

Find all of the female writers

c)

Find all of Elgar's friends

d)

Find all the male writers

e)

Find all the fish

22.

Which SQL statement is used to return only different values?

a)

SELECT UNIQUE

b)

SELECT DISTINCT

c)

SELECT DIFFERENT

23.

With SQL, how can you insert "Olsen" as the "LastName" in the "Persons" table?

a)

INSERT INTO Persons (LastName) VALUES ('Olsen')

b)

INSERT INTO Persons ('Olsen') INTO LastName

c)

INSERT ('Olsen') INTO Persons (LastName)

24.

How can you change "Hansen" into "Nilsen" in the "LastName" column in the Persons table?

a)

MODIFY Persons SET LastName='Nilsen' WHERE LastName='Hansen'

b)

MODIFY Persons SET LastName='Hansen' INTO LastName='Nilsen

c)

UPDATE Persons SET LastName='Hansen' INTO LastName='Nilsen'

d)

UPDATE Persons SET LastName='Nilsen' WHERE LastName='Hansen'

25.

With SQL, how can you delete the records where the "FirstName" is "Peter" in the Persons Table?

a)

DELETE ROW FirstName='Peter' FROM Persons

b)

DELETE FirstName='Peter' FROM Persons

c)

DELETE FROM Persons WHERE FirstName = 'Peter'

26.

With SQL, how can you return the number of records in the "Persons" table?

a)

SELECT NO(*) FROM Persons

b)

SELECT COUNT(*) FROM Persons

c)

SELECT LEN(*) FROM Persons

27.
The HAVING clause does which of the following?
a)
Acts like a WHERE clause but is used for groups rather than columns.
b)
Acts like a WHERE clause but is used for rows rather than columns.
c)
Acts like a WHERE clause but is used for columns rather than groups.
d)
Acts EXACTLY like a WHERE clause.
e)
Acts like a WHERE clause but is used for groups rather than rows.
28.

Which of the following is NOT a GROUP BY function?

a)

MAX

b)

MIN

c)

NVL

d)

AVG

29.

Which of the following functions can be used without GROUP BY clause in SELECT query? (Select all that apply)

a)

COUNT

b)

MAX

c)

MIN

d)

AVG

30.


Which of the following SELECT query returns the department number with maximum salary compensated to an employee? (Consider the table structure as given)

a)

SELECT department_id , max(salary ) FROM employees ;

b)

SELECT department_id , max(salary ) FROM employees GROUP BY department_id ;

c)

SELECT max(salary ) FROM employees GROUP BY department_id ;

d)

SELECT max(salary ) FROM employees ;

31.

Which of the following statements are true about the COUNT function?

a)

The COUNT function counts the number of rows

b)

The COUNT(*) function counts the number of rows with duplicates and NULL values

c)

The COUNT(DISTINCT) function counts the number of distinct rows

d)

COUNT(*) is equivalent to COUNT(ALL)

32.

A table T_COUNT has 12 number values as 1, 2, 3, 32, 1, 1, null, 24, 12, null, 32, null. Predict the output of the below query.

SELECT COUNT (num) FROM t_count;
a)

12

b)

6

c)

9

d)

Throws exception because COUNT function doesn't works with NULL values

33.

A table T_COUNT has 12 number values as 1, 2, 3, 32, 1, 1, null, 24, 12, null, 32, null. Predict the output of the below query.

SELECT COUNT (DISTINCT num) FROM t_count;
a)

12

b)

6

c)

9

d)

Throws exception because COUNT function doesn't works with NULL values

34.
AVG, COUNT, MAX, MIN and SUM are known as what?
a)
Aggregate functions
b)
Wildcard filters
c)
Subqueries
d)
Calculated field
35.
When you select data from 2 tables, you are creating a ________. 
a)
JOIN
b)
PRIMARY KEY
c)
FOREIGN KEY
d)
INDEX
36.

Which SQL keyword is used to sort the result-set?

a)

ORDER

b)

SORT BY

c)

SORT

d)

ORDER BY

37.

With SQL, how can you return all the records from a table named "Persons" sorted descending by "FirstName"?

a)

SELECT * FROM Persons SORT 'FirstName' DESC

b)

SELECT * FROM Persons ORDER BY FirstName DESC

c)

SELECT * FROM Persons SORT BY 'FirstName' DESC

d)

SELECT * FROM Persons ORDER FirstName DESC

38.

Which operator is used to select values within a range?


Next ❯

a)

RANGE

b)

WITHIN

c)

BETWEEN

39.

The NOT NULL constraint enforces a column to not accept empty values.


Next ❯

a)

TRUE

b)

FALSE

40.

Which product is returned in a join query having no join condition?

a)

Equi join

b)

Cartesian

c)

Both Equi joins and Cartesian

d)

Natural

41.

The Cartesian product is also called _________ join

a)

Equi join

b)

Natural

c)

Unrestricted join

d)

Restricted join

42.

In which type of join, the join condition contains an equality operator?

a)

Equi join

b)

Natural

c)

Left join

d)

Right join

43.

In which type of join, the join condition contains an equality operator?

a)

Equi join

b)

Natural

c)

Left join

d)

Right join

44.

In which type of join, duplicate columns are there?

a)

Equi join

b)

Natural

c)

Left join

d)

Right join

45.

With SELECT statement used for joins, the ON subclause produces _______ join

a)

Equi join

b)

Natural

c)

Left join

d)

Right join