wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz on SQL

Total questions: 45

Worksheet time: 45mins

Name
Class
Date
1.

The language used application programs to request data from the DBMS is referred to as __________

a)

DDL

b)

DML

c)

Query Language

d)

All of the mentioned

2.

Which of the following is not a type of SQL statement?

a)

Data Manipulation Language (DML)

b)

Data Definition Language (DDL)

c)

Data Control Language (DCL)

d)

Data Communication Language (DCL)

3.

In existing table, ALTER TABLE statement is used to

a)

Add columns

b)

Add constraints

c)

Delete columns

d)

Delete constrains

e)

All the above

4.

SQL Query to delete all rows in a table without deleting the table (structure, attributes, and indexes)

a)

DELETE FROM table_name;

b)

DELETE TABLE table_name;

c)

DROP TABLE table_name;

d)

None

5.

Correct syntax query syntax to drop a column from a table is

a)

DELETE COLUMN column_name;

b)

DROP COLUMN column_name;

c)

ALTER TABLE table_name DROP COLUMN column_name;

d)

None is correct.

6.

Which command is used for removing a table and all its data from the database:

a)

Create command

b)

Drop table command

c)

Alter table command

d)

All of the mentioned

7.

Which of the following language is used to specify database Schema ?

a)

DDL

b)

DML

c)

DCL

d)

None

8.

Which SQL statement is used to delete data from a database?

a)

DELETE

b)

COLLAPSE

c)

DROP

d)

REMOVE

9.

With SQL, how do you select a column named "FirstName" from a table named "Persons"?

a)

SELECT FirstName FROM Persons

b)

SELECT Persons.FirstName

c)

SELECT Persons Where FirstName

d)

SELECT Persons From FirstName

10.

Which SQL statement is used to insert new data in a database?

a)

ADD RECORD

b)

INSERT INTO

c)

ADD NEW

d)

INSERT NEW

11.

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

a)

SELECT * FROM Persons WHERE FirstName<>'Peter'

b)

SELECT * FROM Persons WHERE FirstName LIKE 'Peter'

c)

SELECT * FROM Persons WHERE FirstName='Peter'

d)

SELECT [all] FROM Persons WHERE FirstName='Peter'

12.

The OR operator displays a record if ANY conditions listed are true. The AND operator displays a record if ALL of the conditions listed are true

a)

True

b)

False

c)

Both A and B

d)

None of these

13.

With SQL, how do you select all the records from a table named "Persons" where the "FirstName" is "Peter" and the "LastName" is "Jackson"?

a)

SELECT * FROM Persons WHERE FirstName='Peter' AND LastName='Jackson'

b)

SELECT * FROM Persons WHERE FirstName<>'Peter' AND LastName<>'Jackson'

c)

SELECT FirstName='Peter', LastName='Jackson' FROM Persons

d)

SELECT*FROM Persons WHERE FirstName='Peter' OR LastName='Jackson'

14.

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"?

a)

SELECT LastName>'Hansen' AND LastName<'Pettersen' FROM Persons

b)

SELECT * FROM Persons WHERE LastName>'Hansen' AND LastName<'Pettersen'

c)

SELECT [all] FROM Persons WHERE LastName>'Hansen' AND LastName<'Pettersen'

d)

SELECT * FROM Persons WHERE LastName BETWEEN 'Hansen' AND 'Pettersen'

15.

With SQL, how can you insert a new record into the "Persons" table?

a)

INSERT ('Jimmy', 'Jackson') INTO Persons

b)

INSERT VALUES ('Jimmy', 'Jackson') INTO Persons

c)

INSERT INTO Persons VALUES ('Jimmy', 'Jackson')

d)

INSERT INTO Persons VALUES

16.

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

a)

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

b)

INSERT ('Olsen') INTO Persons (LastName)

c)

INSERT INTO Persons ('Olsen') INTO LastName

d)

INSERT IN Persons ('Olsen') TO LastName

17.

Which operator is used to select values within a range?

a)

WITHIN

b)

RANGE

c)

ORDER BY

d)

BETWEEN

18.

Which is not a DDL Command?

a)

CREATE

b)

ALTER

c)

DROP

d)

UPDATE

19.

To remove duplicate rows from the results of an SQL SELECT statement, the ________ qualifier specified must be included

a)

ONLY

b)

UNIQUE

c)

DISTINCT

d)

SINGLE

20.

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"?

a)

SELECT * FROM Persons WHERE LastName BETWEEN 'Hansen' AND 'Pettersen'

b)

SELECT * FROM Persons WHERE LastName>'Hansen' AND LastName<'Pettersen'

c)

SELECT LastName>'Hansen' AND LastName<'Pettersen' FROM Persons

21.

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

22.

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

Next ❯

a)

SELECT NO(*) FROM Persons

b)

SELECT COLUMNS(*) FROM Persons

c)

SELECT COUNT(*) FROM Persons

d)

SELECT LEN(*) FROM Persons

23.

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


Next ❯

a)

TRUE

b)

FALSE

24.

Which operator is used to search for a specified pattern in a column?

a)

GET

b)

FROM

c)

LIKE

25.

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%’

26.

In the given query which of the keyword has to be inserted?

INSERT INTO employee _____ (1002,Joey,2000);

a)

Table

b)

Values

c)

Relation

d)

Field

27.

CREATE TABLE employee (id INTEGER,name VARCHAR(20),salary NOT NULL);

INSERT INTO employee VALUES (1005,Rach,0);

INSERT INTO employee VALUES (1007,Ross, );

INSERT INTO employee VALUES (1002,Joey,335);


Some of these insert statements will produce an error. Identify the statement.

a)

Insert into employee values (1005,Rach,0);

b)

Insert into employee values (1002,Joey,335);

c)

Insert into employee values (1007,Ross, );

d)

None of the mentioned

28.

The SQL WHERE clause:

a)

limits the column data that are returned.

b)

limits the row data that are returned.

c)

Both A and B are correct

d)

Neither A nor B is correct

29.

How can you change 'Thomas' to 'Michael' in the LastName column in the user table

a)

UPDATE User SET LastName = 'Thomas' INTO LastName = 'Michel'

b)

MODIFY Users SET LastName = 'Michel' WHERE LastName = 'Thomas'

c)

MODIFY Users SET LastName = 'Thomas' INTO LastName = 'Michel'

d)

UPDATE Users SET LastName = 'Michel' WHERE LastName = 'Thomas'

30.

Which constraint(s) can be used to make sure that the column is not left empty?

a)

NOT NULL

b)

UNIQUE

c)

PRIMARY KEY

d)

ALL THE ABOVE

31.

5. ___________ constraint ensures that no two rows have the same value in the specified columns.

a)

Primary Key

b)

Unique

c)

Default

d)

Check

32.

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

33.

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

34.

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

35.

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

36.

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’);

37.

What is the difference between WHERE and HAVING?

a)

HAVING only applies to aggregate functions like GROUP BY

b)

There are interchangeable

c)

WHERE specifies a GEOGRAPHIC location for a database server

d)

WHERE has limited use

38.

Why make views?

a)

It is faster, safer and better practice to not allow general access to the production database

b)

You should not, they are slow

c)

You should not, they are inefficient

d)

"View" is simply a synonym for the return of the SELECT function

39.

ORDER BY specifies ...................................

a)

the criteria you need to find the information

b)

the table(s) that contain(s) the information

c)

the information you want to find within the database

d)

how the data is organized (sorted) when it is retrieved.

40.

Given the following SQL query, what will be the result of the subquery?

SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);

a)

All employees with salaries less than the average

b)

All employees with salaries greater than the average

c)

An error

41.

Which query returns the total sales amount for each product but includes only products where the total sales exceed $1000?

a)

SELECT product_id, COUNT(amount)

FROM sales

GROUP BY product_id

HAVING COUNT(amount) > 1000;

b)

SELECT product_id, SUM(amount)

FROM sales

WHERE SUM(amount) > 1000

GROUP BY product_id;

c)

SELECT product_id, SUM(amount)

FROM sales

GROUP BY product_id

HAVING SUM(amount) > 1000;

d)

SELECT product_id, SUM(amount)

FROM sales

GROUP BY product_id

WHERE SUM(amount) > 1000;

42.

Which SQL query will return the second-highest salary from the employees table?

a)

SELECT MAX(salary)

FROM employees

WHERE salary < (SELECT MAX(salary) FROM employees);

b)

SELECT MAX(salary)

FROM employees

ORDER BY salary DESC

LIMIT 1, 1;

c)

SELECT salary

FROM employees

ORDER BY salary DESC

LIMIT 1 OFFSET 1;

d)

SELECT salary

FROM employees

WHERE salary < MAX(salary);

43.

Which join refers to join records from the right table that have no matching key in the left table are include in the result set:

a)

Left outer join

b)

Right outer join

c)

Full outer join

d)

None of the above

44.

Which join is to be used between two tables A and B when the resultant table needs rows from A and B that matches the condition and rows from A that does not match the condition?

a)

Outer Join

b)

Cross Join

c)

Inner Join

d)

None of the above

45.

Which of the following statements are true?

a)

INNER JOIN only retrieves those rows from Cartesian Product that satisfy the JOIN condition

b)

FULL OUTER JOIN is same as CROSS JOIN

c)

SELF JOIN is a special type of OUTER JOIN

d)

Both A and C