Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

SQL FINAL TEST 1

Total questions: 75

Worksheet time: 3hrs 30mins

Name
Class
Date
1.

Which would show all fields from the Pupils table?

a)

SELECT * FROM Pupils

b)

SELECT Name, Form FROM Pupils

c)

SELECT * FROM *

d)

SELECT * FROM Forms

2.

Which Symbol means "All"

a)

*

b)

&

c)

%

d)

!

3.

Which would find pupils with "er" anywhere in their name?

a)

SELECT * FROM Pupils Where Name = "%er"

b)

SELECT * FROM Pupils Where Name = "$er$"

c)

SELECT * FROM Pupils Where Name = "%er%"

d)

SELECT * FROM Pupils Where Name = "er%"

4.

Choose the correct query

a)

SELECT * FROM EMP WHERE NAME=NULL

b)

SELECT * FROM EMP WHERE NAME IS NULL;

c)

SELECT FROM EMP WHERE NAME IS NULL;

d)

SELECT *FROM EMP WHERE NAME IS 'NULL';

5.

The restrictions or conditions applied on data are known as (a)  

6.

The primary key of a table which is present in another table for referencing is known as (a)  

7.

What will be the output?

SELECT ROUND(36.7894,2)

a)

36.78

b)

38.79

c)

36.7

d)

36

8.

What will be the output?

SELECT TRUNCATE(36.5643,2);

a)

36.56

b)

36.57

c)

36.5643

d)

36

9.

Which is the correct query to delete the rows of employees whose exp is less than 10.

a)

DELETE * FROM EMP WHERE EXP<10;

b)

DELETE FROM EMP;

c)

DELETE FROM EMP WHERE EXP<10;

d)

DELETE FROM EMP WHERE EXP>10;

10.

Which is not an aggregate function?

a)

SUM()

b)

POW()

c)

AVG()

d)

COUNT()

11.
A column in a database
a)
record
b)
row
c)
field
d)
data
12.
Return all dramas made after 2004.
a)
SELECT * FROM movies WHERE genre = 'drama';
b)
SELECT * FROM movies WHERE genre = 'drama' AND year > 2004;
c)
SELECT * FROM movies WHERE genre = "drama' AND year < 2004;
d)
SELECT * FROM movies WHERE imdb_rating = 7 AND LIMIT = 7
13.


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 ;

14.

Predict the outcome of the below query

SELECT department_id ,avg(salary )
FROM employees 
HAVING avg(salary )>2000
GROUP BY department_id 
ORDER BY department_id 
a)

It executes successfully.

b)

It throws error because HAVING clause precedes the GROUP BY clause.

c)

It throws error because HAVING clause uses the aggregate function.

d)

It executes but no results are displayed because HAVING clause precedes the GROUP BY clause.

15.

Which clause should you use to exclude group results in a query using group functions?

a)

WHERE

b)

HAVING

c)

GROUP BY

d)

ORDER BY

16.

Predict the outcome of the below query

SELECT department_id , COUNT(first_name )
FROM employees 
WHERE job IN ('SALESMAN','CLERK','MANAGER','ANALYST')
GROUP BY department_id 
HAVING AVG(salary ) BETWEEN 2000 AND 3000;
a)

It returns an error because the BETWEEN operator cannot be used in the HAVING clause.

b)

It returns an error because WHERE and HAVING clauses cannot be used in the same SELECT statement.

c)

It returns an error because WHERE and HAVING clauses cannot be used to apply conditions on the same column.

d)

It executes successfully.

17.

What will be the output of the query :

Select Substring('mysql application',3,3)

a)

app

b)

mysql

c)

application

d)

sql

18.

What will be the output of the following query:

Select round(59999.99,-2);

a)

59999

b)

59900

c)

60000

d)

59990

19.

Which function will be used to remove only the trailing spaces from a string?

a)

ltrim()

b)

rtrim()

c)

trim()

d)

all

20.

Fill in the blank:

___________________ this clause is used to apply condition on all the rows of table.

a)

Where

b)

Having

c)

Order By

d)

Sort By

21.

Fill in the blank:

(a)   this clause is used with GROUP BY to filter the group of records.

22.

What will be the output of following query:

Select length(trim(' exam '));

a)

exam

b)

exam

c)

6

d)

4

23.

Difference between ALTER Table command and UPDATE command :

a)

ALTER is DDL command and is used for modifying the schema of table

b)

UPDATE is DML command and is

used for modifying the existing data of table

c)

Using Alter command any value inside the table can be modified.

d)

Using Update command columns of a table can be renamed.

24.

Which clause is used when we want to use aggregate functions in conditions?

a)

Where

b)

Group By

c)

Having

d)

Both 2 and 3

25.

Match SQL language with SQL commands

1)DDL i)Revok, Grant

2)DML ii)rename a table

3)TCL iii)insert, update

4)DCL iv)rollback , commit

a)

1-iii,2-i,3-ii,4-iv

b)

1-iii,2-ii,3-iv,4-i

c)

1-ii,2-iii,3-iv,4-i

d)

1-i,2-iii,3-ii,4-iv

26.

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

27.

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

28.

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

29.

The primary key of a table which is present in another table for referencing is known as (a)  

30.
A particular DBMS uses SQL for extracting data. The SQL command "WHERE" is usually followed by:
a)
a criteria
b)
a table name
c)
a user name
d)
a mathematical formula
31.

From the items_ordered table, select a list of all items purchased for customerid 10449. Display the customerid, item, and price for this customer.

(a)  

32.

Select all columns from the items_ordered table for whoever purchased a Tent

(a)  

33.

Select the customerid, order_date, and item values from the items_ordered table for any items in the item column that start with the letter “S”.

(a)  

34.

Select the lastname, firstname, and city for all customers in the customers table. Display the results in Ascending Order based on the lastname.

(a)  

35.

Select the item and price for all of the items in the items_ordered table that the price is greater than 10.00. Display the results in descending order based on the price.

(a)  

36.

Select the item and price of all items that start with the letters ‘S’, ‘P’, or ‘F’

(a)  

37.

Select the date, item, and price from the items_ordered table for all of the rows that have a price value ranging from 10.00 to 80.00.

(a)  

38.

Select the firstname, city, and state from the customers table for all of the rows where the state value is either: Arizona, Washington, Oklahoma, Colorado, or Hawaii.

(a)  

39.

Select the customerid, firstname, lastname, order_date, item, and price for everything each customer purchased in the items_ordered table.(HINT : use ALIASES c for customer and i for items_ordered)

(a)  

40.

In a LIKE clause, you can could ask for any value ending in “ton” by writing

a)

LIKE ton$

b)

LIKE ^.*ton$

c)

LIKE %ton

d)

LIKE *ton

41.

In a LIKE clause, you can ask for any 6 letter value by writing:

a)

LIKE ??????

b)

LIKE .{6}

c)

LIKE …… (that’s six dots)

d)

LIKE ______ (that’s six underscore characters)

42.

Which statement is used to count number of rows in table?

a)

SELECT COUNT(*) FROM table_name;

b)

SELECT COUNT ALL(*) FROM table_name;

c)

SELECT ROWS(*) FROM table_name;

d)

All the above

43.

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

44.

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

45.

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

46.

______________ constraint prevents NULL values

a)

UNIQUE

b)

NOT NULL

c)

NULL

d)

FOREIGN KEY

47.

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

a)

TRUE

b)

FALSE

48.

What is the correct order of clauses in a SQL statement?

a)

SELECT, FROM, ORDER BY, WHERE

b)

SELECT, FROM, WHERE, ORDER BY

c)

SELECT, WHERE, FROM, ORDER BY

d)

WHERE, FROM, SELECT, ORDER BY

49.

With SQL how can I return all items in the Item table sorted from the lowest priced to the highest priced?

a)

SELECT * FROM Items ORDER BY Price ASCENDING

b)

SELECT * FROM Items ORDER BY Price ASC

c)

SELECT * FROM Items BY Price LOWEST TO HIGHEST

d)

SELECT * FROM Items ORDER BY Price DESC

50.

How would you DELETE records from the Items table with a "Chair" Type?

a)

DELETE 'Chair' FROM Items

b)

DELETE Type FROM Items WHERE Type = 'Chair'

c)

DELETE FROM Items WHERE Type = 'Chair'

d)

DELETE ITEMS WHERE Type = 'Chair'

51.

How would you display Chairs in the Items table that have a Price greater than £50.

a)

SELECT * FROM Items WHERE Type = 'Chair' AND Price > 50

b)

SELECT * FROM Items WHERE Type = 'Chair' OR Price < 100

c)

SELECT * FROM Iterms WHERE Type = 'Chair' AND Price >= 50

d)

SELECT * FROM Items WHERE Price > 50

52.

Which query can be used to get the above result?

a)

SELECT e.fname as employee, m.fname as manager

FROM emp e INNER JOIN emp m

ON e.manager_id=m.empno;

b)

SELECT e.fname as employee, m.fname as manager

FROM emp1 e INNER JOIN emp2 m

ON e.manager_id=m.empno;

c)

SELECT e.fname as employee, m.fname as manager

FROM emp2 e INNER JOIN emp1 m

ON e.manager_id=m.empno;

d)

SELECT e.fname as employee, m.fname as manager

FROM emp e, emp m

ON e.manager_id=m.empno;

53.

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

54.

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'

55.

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

56.

What is the most common JOIN statement used in business?

a)

Inner Join

b)

Left Join

c)

Right Join

d)

Full Outer Join

57.

Which join would you use to create a query that returns ALL data from Table B and only those on Table A that match?

a)

Inner Join

b)

Left Join

c)

Right Join

d)

Full Outer Join

58.

________ is a subquery.

a)

Sub part of a query

b)

Query within the query

c)

Clause

d)

None of the above

59.

Which is/are part of subquery?

a)

Inner query

b)

Outer query

c)

Both Inner query & Outer query

d)

None of the above

60.

Which of the following WHERE clauses statements is valid?

a)

WHERE A2 IN (SELECT B2 ...

b)

WHERE A2 EXISTS (SELECT B2 ...

c)

WHERE EXISTS (SELECT B2 ...

d)

WHERE A2 EXISTS IN (SELECT B2...

61.

Identify the SELECT statements that execute successfully

a)

SELECT first_name, last_name, job_id, salary*12 AS Yearly Sal

FROM employees;

b)

SELECT first_name, last_name, job_id, salary*12 "yearly sal"

FROM employees;

c)

SELECT first_name, last_name, job_id, salary AS "yearly sal"

FROM employees;

d)

SELECT first_name+last_name AS name, job_Id, salary*12 yearly sal

FROM employees;

62.

You can use constraints to do the following:

a)

Enforce rules on the data in a table whenever a row is inserted, updated, or deleted.

b)

Prevent the deletion of a table.

c)

Prevent the creation of a table.

d)

Prevent the creation of data in a table.

63.

What is a foreign key?

a)

A FOREIGN KEY is a field in one table that matches the PRIMARY KEY in another table.

b)

A foreign key is a field in a table that uniquely defines every record uniquely

64.

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

65.

6. ___________ which helps to uniquely identify a record.

a)

Primary key Constraint

b)

Unique Constraint

c)

Default constraint

d)

Check constraint

66.

7. _________ helps to set a limit value placed for a field.

a)

DEFAULT Constraint

b)

Primary Key Constraint

c)

Check Constraint

d)

TABLE CONSTRAINT

67.

SELECT * FROM cars WHERE Doors > 3

would return how many records?

a)

1

b)

2

c)

3

d)

4

68.

SELECT * FROM Students WHERE Gender="Female" AND Class=2.2

would return how many records?

a)

1

b)

2

c)

3

d)

4

69.

Repetition of data is called data ..............

a)

dependance

b)

redundancy

c)

inconsistency

d)

isolation

70.

A ............ is an organized collection of structured data.

a)

information

b)

file

c)

database

d)

DBMS

71.

A database ............... is a sketch of design of a planned data.

a)

instance

b)

schema

c)

metadata

d)

relation

72.

A data ................ is a set of rules that define valid data.

a)

constraint

b)

data dictionary

c)

query

d)

all of these

73.

A relational database consists of a collection of ..............

a)

tables

b)

fields

c)

records

d)

keys

74.

Data redundancy may lead to data inconsistency.

a)

True

b)

False

75.

This symbol is placed immediately after the SELECT command to display all the fields.

a)

$

b)

%

c)

=

d)

*