wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

SQL and Relational Algebra Worksheet (Grade 12)

Total questions: 65

Worksheet time: 33mins

Name
Class
Date
1.

Which join type results in a Cartesian product?

a)

FULL OUTER JOIN

b)

RIGHT JOIN

c)

CROSS JOIN

d)

LEFT JOIN

2.

Which operator is used to combine the result sets of two or more SELECT queries, removing duplicates?

a)

EXCEPT

b)

INTERSECT

c)

UNION

d)

JOIN

3.

Which type of join includes all rows from the left table and only the matching rows from the right table?

a)

LEFT JOIN

b)

FULL JOIN

c)

RIGHT JOIN

d)

INNER JOIN

4.

What is the syntax to rename a column in a SELECT statement using an alias?

a)

SELECT alias_name FROM column_name

b)

RENAME column_name TO alias_name

c)

SELECT column_name AS alias_name

d)

WITH column_name AS alias_name

5.

Which SQL function returns the sum of values in a column?

a)

SUM()

b)

COUNT()

c)

AVG()

d)

MIN()

6.

What is the purpose of using aliases in SQL?

a)

To filter data

b)

To delete records from tables

c)

To provide temporary names for columns or tables for easier reference

d)

To create new columns in a result set

7.

What is the correct syntax for using the UNION keyword in SQL?

a)

SELECT * FROM tableA EXCEPT SELECT * FROM tableB;

b)

SELECT * FROM tableA UNION SELECT * FROM tableB;

c)

SELECT * FROM tableA JOIN tableB;

d)

SELECT * FROM tableA UNION ALL SELECT * FROM tableB;

8.

How can you rename a table while writing a query using SQL?

a)

Use the RENAME keyword

b)

Use the AS keyword

c)

Use the SET clause

d)

Use the WITH clause

9.

What is the purpose of the HAVING clause in SQL?

a)

To limit the number of rows returned

b)

To sort the results

c)

To join multiple tables

d)

To filter group results returned by the GROUP BY clause

10.

With SQL, how do you select all the records from a table named "Persons" where the value of the column "FirstName" starts 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%;

11.

Which SQL statement selects all rows from a table called "Customers" and orders the result by "customer name"?

a)

SELECT * FROM Customers ORDER ON customer_name;

b)

SELECT * FROM Customers ORDER customer_name;

c)

SELECT * FROM Customers ORDERED customer_name;

d)

SELECT * FROM Customers ORDER BY customer_name;

12.

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

a)

None of the given

b)

SELECT Persons.FirstName;

c)

EXTRACT FirstName FROM Persons;

d)

SELECT FirstName FROM Persons;

13.

Which SQL keyword is used to retrieve a maximum value?

a)

MAX

b)

MOST

c)

UPPER

d)

TOP

14.

Which SQL keyword is used to sort the result set?

a)

SORT BY

b)

SORT

c)

ORDER BY

d)

FILTER

15.

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 [all] FROM Persons WHERE FirstName='Peter';

b)

SELECT [all] FROM Persons WHERE FirstName LIKE 'Peter';

c)

SELECT * FROM Persons WHERE FirstName='Peter';

d)

SELECT * FROM Persons WHERE FirstName<>'Peter';

16.

What is meant by the term union compatibility?

a)

When two or more tables share the same (or compatible) domains

b)

When two or more tables share the same number of columns and when they share the same domains

c)

When two or more tables share the same number of columns

d)

None of the given

17.

Which of the following is the correct order of keywords for SQL SELECT statements?

a)

FROM, WHERE, SELECT

b)

SELECT, WHERE, FROM

c)

SELECT, FROM, WHERE

d)

WHERE, FROM, SELECT

18.

What is meant by the following relational algebra statement: STUDENT X COURSE

a)

Compute the left outer join between the STUDENT and COURSE relations

b)

Compute the full outer join between the STUDENT and COURSE relations

c)

Compute the right outer join between the STUDENT and COURSE relations

d)

Compute the cartesian product between the STUDENT and COURSE relations

19.

What is a characteristic of a CROSS JOIN in SQL?

a)

Returns all rows from the left table and only matching rows from the right table

b)

Returns only rows with matching keys

c)

Returns a Cartesian product of the two tables

d)

Returns rows where the join condition is satisfied

20.

Which clause should be used to specify the order of rows in SQL based on multiple columns?

a)

ORDER BY

b)

GROUP BY

c)

HAVING

d)

JOIN

21.

In SQL, what does the CAST function do?

a)

Converts a value from one data type to another

b)

Combines two tables into one

c)

Removes rows with null values

d)

Renames a table

22.

Which SQL function is used to concatenate strings in PostgreSQL?

a)

||

b)

&

c)

+

d)

CONCAT()

23.

Which of the SQL statements is correct?

a)

SELECT Username AND Password FROM Users

b)

None of the given

c)

SELECT Username, Password WHERE Username = 'user1'

d)

SELECT Username, Password FROM Users

24.

List all operations of relation algebra in the query: SELECT accountId FROM Account;

a)

Selection

b)

Projection, selection

c)

Projection

d)

Projection, union

25.

Which operator is used in SQL for partial string matching?

a)

BETWEEN

b)

IN

c)

NOT IN

d)

LIKE

26.

Which type of join returns all rows from both tables, filling in NULLs where there are no matches?

a)

LEFT JOIN

b)

INNER JOIN

c)

CROSS JOIN

d)

FULL OUTER JOIN

27.

What keyword can you use to search for a string in a column?

a)

HAS STRING

b)

CONTAINS STRING

c)

LIKE

d)

FIND STRING

28.

Which of the following is not a relational algebra operation?

a)

Selection

b)

Manipulation

c)

Union

d)

Projection

29.

What is the purpose of the SQL AS clause?

a)

None of the given

b)

The AS SQL clause is used to change the name of a column in the result set

c)

The AS clause defines a search condition

d)

The AS clause is used with the aggregate functions only

30.

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 LastName='Jackson';

c)

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

d)

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

31.

Which of the following is used to denote the selection operation in relational algebra?

a)

Pi (Greek)

b)

Omega (Greek)

c)

Lambda (Greek)

d)

Sigma (Greek)

32.

A subquery in an SQL SELECT statement is enclosed in:

a)

braces - {...}

b)

parenthesis - (...)

c)

CAPITAL LETTERS

d)

brackets - [...]

33.

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

a)

SELECT * FROM Persons SORT BY 'FirstName' DESC;

b)

SELECT * FROM Persons SORT 'FirstName' DESC;

c)

SELECT * FROM Persons ORDER BY FirstName DESC;

d)

SELECT * FROM Persons ORDER FirstName DESC;

34.

What does the term "Normalization" refer to in database design?

a)

Creating backups of database tables

b)

Adding new tables to a database

c)

Organizing a database to reduce redundancy and improve data integrity

d)

Optimizing the performance of SQL queries

35.

What does the TIMESTAMP data type in SQL store?

a)

A boolean value

b)

Both date and time

c)

Only the date

d)

Only the time

36.

Which of the following is true about SQL keywords?

a)

SQL keywords are not case-sensitive

b)

SQL keywords cannot be used in queries

c)

SQL keywords must be written in lowercase

d)

SQL keywords are case-sensitive

37.

In SQL, what does the command ALTER TABLE table_name DROP COLUMN column_name; do?

a)

Deletes the entire table

b)

Deletes data from the table

c)

Deletes a specific column from the table

d)

Deletes a specific row

38.

In a database, which of the following is an example of a subject area?

a)

Database backup procedures

b)

SQL queries

c)

Teachers, students, and courses

d)

Rows and columns in a table

39.

In an ER diagram, what is represented by a rectangle?

a)

An attribute

b)

An entity

40.

In database design, what is a conceptual model?

a)

A visual representation of entities and relationships

b)

A list of SQL commands

c)

The final database structure

d)

A table schema

41.

Which SQL keyword is used to enforce a condition that a column cannot contain NULL values?

a)

NOT NULL

b)

PRIMARY KEY

c)

UNIQUE

d)

CHECK

42.

What is a partial dependency in database design?

a)

When a non-key attribute depends on only part of a composite key

b)

When a foreign key links two tables

c)

When a column can store multiple values

d)

When a primary key is not unique

43.

In SQL, which of the following is a character data type?

a)

BOOLEAN

b)

CHAR

c)

INT

d)

DATE

44.

In SQL, how do you ensure that a column must always have a value?

a)

By adding the FOREIGN KEY constraint

b)

By adding the NOT NULL constraint

c)

By adding the CHECK constraint

d)

By adding the UNIQUE constraint

45.

What is the purpose of the SELECT statement in SQL?

a)

To modify existing records

b)

To create a new table

c)

To delete data

d)

To retrieve data from a database

46.

Which of the following is a "bad" design for a database table?

a)

A table without NULL values

b)

A table with redundant data

c)

A table with atomic values

d)

A table with a foreign key

47.

In SQL, which of the following commands is used to remove a table from the database?

a)

REMOVE TABLE

b)

DELETE TABLE

c)

ALTER TABLE

d)

DROP TABLE

48.

What does the UNIQUE constraint ensure in a database table?

a)

All values in a column must be unique

b)

A column can store multiple values

c)

All values in a column must be NULL

d)

A column can have repeated values

49.

What is a Primary Key (PK)?

a)

A field that connects two tables

b)

A field that stores multiple values

c)

A field that contains NULL values

d)

A field that uniquely identifies a row in a table

50.

What type of constraint would be used to ensure that students' birthdates are after 1980?

a)

UNIQUE

b)

PRIMARY KEY

c)

NOT NULL

d)

CHECK

51.

Which command is used to modify a column's data type in SQL?

a)

ALTER TABLE

b)

CHANGE COLUMN

c)

UPDATE TABLE

d)

MODIFY TABLE

52.

What is the purpose of the SELECT statement in SQL?

a)

To retrieve data from a database

b)

To modify existing records

c)

To create a new table

d)

To delete data

53.

Which SQL command is used to retrieve data from a database?

a)

UPDATE

b)

SELECT

c)

INSERT

d)

DELETE

54.

What is the first stage in database design?

a)

Logical design

b)

Subject Area Analysis

c)

Conceptual design

d)

Physical design

55.

What is the primary function of the DROP TABLE command?

a)

It removes a column from a table

b)

It removes a table and all its data from the database

c)

It deletes data from a table

d)

It modifies the structure of a table

56.

Which of the following is included in the database design stages?

a)

Market analysis, user analysis, testing

b)

Coding, debugging, deployment

c)

Subject Area Analysis, Conceptual Design, Logical Design, Physical Design

d)

Software testing, documentation, release

57.

What does the INSERT command do in SQL?

a)

Modifies existing data

b)

Adds new records to a table

c)

Deletes data from a table

d)

Selects records from a table

58.

What is the purpose of a foreign key in a relational database?

a)

To act as a primary key

b)

To uniquely identify a table

c)

To store NULL values

d)

To create a link between two tables

59.

Which of the following SQL data types is used for storing large text values?

a)

BOOLEAN

b)

TEXT

c)

INT

d)

VARCHAR

60.

In database design, what is a conceptual model?

a)

A table schema

b)

A list of SQL commands

c)

The final database structure

d)

A visual representation of entities and relationships

61.

What is the function of the CHECK constraint in SQL?

a)

To ensure that all data in a column meets a specific condition

b)

To create relationships between tables

c)

To allow NULL values in a column

d)

To delete a record from a table

62.

What happens when you use the WHERE clause in an SQL UPDATE command?

a)

It creates new rows in the table

b)

It deletes rows that match the condition

c)

It updates all rows in the table

d)

It specifies which rows to update based on a condition

63.

What does the ALTER TABLE command allow you to do?

a)

Modify the structure of an existing table

b)

Delete records from a table

c)

Query data from multiple tables

d)

Create a new database

64.

What is an example of a database management system (DBMS)?

a)

PostgreSQL

b)

HTML

c)

Google

d)

JavaScript

65.

Which SQL operator is used to compare a value against a set of values returned by a subquery?

a)

IN

b)

HAVING

c)

LIKE

d)

BETWEEN