NEW
Font size
WorksheetsSQL and Relational Algebra Worksheet (Grade 12)
Total questions: 65
Worksheet time: 33mins
Which join type results in a Cartesian product?
FULL OUTER JOIN
RIGHT JOIN
CROSS JOIN
LEFT JOIN
Which operator is used to combine the result sets of two or more SELECT queries, removing duplicates?
EXCEPT
INTERSECT
UNION
JOIN
Which type of join includes all rows from the left table and only the matching rows from the right table?
LEFT JOIN
FULL JOIN
RIGHT JOIN
INNER JOIN
What is the syntax to rename a column in a SELECT statement using an alias?
SELECT alias_name FROM column_name
RENAME column_name TO alias_name
SELECT column_name AS alias_name
WITH column_name AS alias_name
Which SQL function returns the sum of values in a column?
SUM()
COUNT()
AVG()
MIN()
What is the purpose of using aliases in SQL?
To filter data
To delete records from tables
To provide temporary names for columns or tables for easier reference
To create new columns in a result set
What is the correct syntax for using the UNION keyword in SQL?
SELECT * FROM tableA EXCEPT SELECT * FROM tableB;
SELECT * FROM tableA UNION SELECT * FROM tableB;
SELECT * FROM tableA JOIN tableB;
SELECT * FROM tableA UNION ALL SELECT * FROM tableB;
How can you rename a table while writing a query using SQL?
Use the RENAME keyword
Use the AS keyword
Use the SET clause
Use the WITH clause
What is the purpose of the HAVING clause in SQL?
To limit the number of rows returned
To sort the results
To join multiple tables
To filter group results returned by the GROUP BY clause
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"?
SELECT * FROM Persons WHERE FirstName='a';
SELECT * FROM Persons WHERE FirstName LIKE 'a%';
SELECT * FROM Persons WHERE FirstName LIKE '%a';
SELECT * FROM Persons WHERE FirstName=%a%;
Which SQL statement selects all rows from a table called "Customers" and orders the result by "customer name"?
SELECT * FROM Customers ORDER ON customer_name;
SELECT * FROM Customers ORDER customer_name;
SELECT * FROM Customers ORDERED customer_name;
SELECT * FROM Customers ORDER BY customer_name;
With SQL, how do you select a column named "FirstName" from a table named "Persons"?
None of the given
SELECT Persons.FirstName;
EXTRACT FirstName FROM Persons;
SELECT FirstName FROM Persons;
Which SQL keyword is used to retrieve a maximum value?
MAX
MOST
UPPER
TOP
Which SQL keyword is used to sort the result set?
SORT BY
SORT
ORDER BY
FILTER
With SQL, how do you select all the records from a table named "Persons" where the value of the column "FirstName" is "Peter"?
SELECT [all] FROM Persons WHERE FirstName='Peter';
SELECT [all] FROM Persons WHERE FirstName LIKE 'Peter';
SELECT * FROM Persons WHERE FirstName='Peter';
SELECT * FROM Persons WHERE FirstName<>'Peter';
What is meant by the term union compatibility?
When two or more tables share the same (or compatible) domains
When two or more tables share the same number of columns and when they share the same domains
When two or more tables share the same number of columns
None of the given
Which of the following is the correct order of keywords for SQL SELECT statements?
FROM, WHERE, SELECT
SELECT, WHERE, FROM
SELECT, FROM, WHERE
WHERE, FROM, SELECT
What is meant by the following relational algebra statement: STUDENT X COURSE
Compute the left outer join between the STUDENT and COURSE relations
Compute the full outer join between the STUDENT and COURSE relations
Compute the right outer join between the STUDENT and COURSE relations
Compute the cartesian product between the STUDENT and COURSE relations
What is a characteristic of a CROSS JOIN in SQL?
Returns all rows from the left table and only matching rows from the right table
Returns only rows with matching keys
Returns a Cartesian product of the two tables
Returns rows where the join condition is satisfied
Which clause should be used to specify the order of rows in SQL based on multiple columns?
ORDER BY
GROUP BY
HAVING
JOIN
In SQL, what does the CAST function do?
Converts a value from one data type to another
Combines two tables into one
Removes rows with null values
Renames a table
Which SQL function is used to concatenate strings in PostgreSQL?
||
&
+
CONCAT()
Which of the SQL statements is correct?
SELECT Username AND Password FROM Users
None of the given
SELECT Username, Password WHERE Username = 'user1'
SELECT Username, Password FROM Users
List all operations of relation algebra in the query: SELECT accountId FROM Account;
Selection
Projection, selection
Projection
Projection, union
Which operator is used in SQL for partial string matching?
BETWEEN
IN
NOT IN
LIKE
Which type of join returns all rows from both tables, filling in NULLs where there are no matches?
LEFT JOIN
INNER JOIN
CROSS JOIN
FULL OUTER JOIN
What keyword can you use to search for a string in a column?
HAS STRING
CONTAINS STRING
LIKE
FIND STRING
Which of the following is not a relational algebra operation?
Selection
Manipulation
Union
Projection
What is the purpose of the SQL AS clause?
None of the given
The AS SQL clause is used to change the name of a column in the result set
The AS clause defines a search condition
The AS clause is used with the aggregate functions only
With SQL, how do you select all the records from a table named "Persons" where the "FirstName" is "Peter" and the "LastName" is "Jackson"?
SELECT * FROM Persons WHERE FirstName='Peter' AND LastName='Jackson';
SELECT * FROM Persons WHERE LastName='Jackson';
SELECT FirstName='Peter', LastName='Jackson' FROM Persons;
SELECT * FROM Persons WHERE FirstName<>'Peter' AND LastName<>'Jackson';
Which of the following is used to denote the selection operation in relational algebra?
Pi (Greek)
Omega (Greek)
Lambda (Greek)
Sigma (Greek)
A subquery in an SQL SELECT statement is enclosed in:
braces - {...}
parenthesis - (...)
CAPITAL LETTERS
brackets - [...]
With SQL, how can you return all the records from a table named "Persons" sorted descending by "FirstName"?
SELECT * FROM Persons SORT BY 'FirstName' DESC;
SELECT * FROM Persons SORT 'FirstName' DESC;
SELECT * FROM Persons ORDER BY FirstName DESC;
SELECT * FROM Persons ORDER FirstName DESC;
What does the term "Normalization" refer to in database design?
Creating backups of database tables
Adding new tables to a database
Organizing a database to reduce redundancy and improve data integrity
Optimizing the performance of SQL queries
What does the TIMESTAMP data type in SQL store?
A boolean value
Both date and time
Only the date
Only the time
Which of the following is true about SQL keywords?
SQL keywords are not case-sensitive
SQL keywords cannot be used in queries
SQL keywords must be written in lowercase
SQL keywords are case-sensitive
In SQL, what does the command ALTER TABLE table_name DROP COLUMN column_name; do?
Deletes the entire table
Deletes data from the table
Deletes a specific column from the table
Deletes a specific row
In a database, which of the following is an example of a subject area?
Database backup procedures
SQL queries
Teachers, students, and courses
Rows and columns in a table
In an ER diagram, what is represented by a rectangle?
An attribute
An entity
In database design, what is a conceptual model?
A visual representation of entities and relationships
A list of SQL commands
The final database structure
A table schema
Which SQL keyword is used to enforce a condition that a column cannot contain NULL values?
NOT NULL
PRIMARY KEY
UNIQUE
CHECK
What is a partial dependency in database design?
When a non-key attribute depends on only part of a composite key
When a foreign key links two tables
When a column can store multiple values
When a primary key is not unique
In SQL, which of the following is a character data type?
BOOLEAN
CHAR
INT
DATE
In SQL, how do you ensure that a column must always have a value?
By adding the FOREIGN KEY constraint
By adding the NOT NULL constraint
By adding the CHECK constraint
By adding the UNIQUE constraint
What is the purpose of the SELECT statement in SQL?
To modify existing records
To create a new table
To delete data
To retrieve data from a database
Which of the following is a "bad" design for a database table?
A table without NULL values
A table with redundant data
A table with atomic values
A table with a foreign key
In SQL, which of the following commands is used to remove a table from the database?
REMOVE TABLE
DELETE TABLE
ALTER TABLE
DROP TABLE
What does the UNIQUE constraint ensure in a database table?
All values in a column must be unique
A column can store multiple values
All values in a column must be NULL
A column can have repeated values
What is a Primary Key (PK)?
A field that connects two tables
A field that stores multiple values
A field that contains NULL values
A field that uniquely identifies a row in a table
What type of constraint would be used to ensure that students' birthdates are after 1980?
UNIQUE
PRIMARY KEY
NOT NULL
CHECK
Which command is used to modify a column's data type in SQL?
ALTER TABLE
CHANGE COLUMN
UPDATE TABLE
MODIFY TABLE
What is the purpose of the SELECT statement in SQL?
To retrieve data from a database
To modify existing records
To create a new table
To delete data
Which SQL command is used to retrieve data from a database?
UPDATE
SELECT
INSERT
DELETE
What is the first stage in database design?
Logical design
Subject Area Analysis
Conceptual design
Physical design
What is the primary function of the DROP TABLE command?
It removes a column from a table
It removes a table and all its data from the database
It deletes data from a table
It modifies the structure of a table
Which of the following is included in the database design stages?
Market analysis, user analysis, testing
Coding, debugging, deployment
Subject Area Analysis, Conceptual Design, Logical Design, Physical Design
Software testing, documentation, release
What does the INSERT command do in SQL?
Modifies existing data
Adds new records to a table
Deletes data from a table
Selects records from a table
What is the purpose of a foreign key in a relational database?
To act as a primary key
To uniquely identify a table
To store NULL values
To create a link between two tables
Which of the following SQL data types is used for storing large text values?
BOOLEAN
TEXT
INT
VARCHAR
In database design, what is a conceptual model?
A table schema
A list of SQL commands
The final database structure
A visual representation of entities and relationships
What is the function of the CHECK constraint in SQL?
To ensure that all data in a column meets a specific condition
To create relationships between tables
To allow NULL values in a column
To delete a record from a table
What happens when you use the WHERE clause in an SQL UPDATE command?
It creates new rows in the table
It deletes rows that match the condition
It updates all rows in the table
It specifies which rows to update based on a condition
What does the ALTER TABLE command allow you to do?
Modify the structure of an existing table
Delete records from a table
Query data from multiple tables
Create a new database
What is an example of a database management system (DBMS)?
PostgreSQL
HTML
JavaScript
Which SQL operator is used to compare a value against a set of values returned by a subquery?
IN
HAVING
LIKE
BETWEEN
