Font size
WorksheetsSQL Review Quiz
Total questions: 79
Worksheet time: 40mins
Which clause can specify rows for aggregate functions?
INSERT clause
WHERE clause
SELECT clause
DELETE clause
What do aggregate queries construct from a table?
New tables
New cells
New columns
New rows
Which aggregate function is used to find the maximum value in a column?
AVG(value)
MIN(value)
MAX(value)
SUM(value)
What SQL keyword is used to provide more meaningful names to result sets?
ALIAS
TITLE
AS
NAME
Why might you use an ALIAS in a SQL query?
To provide more meaningful names
To make the query run faster
To delete duplicate data
To change the data type
What is the primary use of the GROUP BY clause in SQL?
To sort records
To group records with the same values
To delete records
To filter records
What is the purpose of using aliases in SQL queries?
To rename columns or results
To rename tables
To join tables
To delete data
What does the following SQL query do: SELECT MIN(dateOrdered) FROM orders?
Counts the number of dates in the dateOrdered column
Finds the latest date in the dateOrdered column
Finds the earliest date in the dateOrdered column
Sums up all the dates in the dateOrdered column
What does the AVG function do in SQL?
Calculates the sum of values
Finds the maximum value
Finds the minimum value
Calculates the average of values
Which of the following SQL statements correctly uses the COUNT function to count all rows in a table called employees?
SELECT COUNT(NULL) FROM employees;
SELECT COUNT(DISTINCT employee_id) FROM employees;
SELECT COUNT(*) FROM employees;
SELECT COUNT(employee_id) FROM employees;
Which of the following aggregate functions will return the highest value of a column named salary in a table named employees? (Select all that apply)
SELECT MAX(salary) FROM employees;
SELECT MIN(salary) FROM employees;
SELECT AVG(salary) FROM employees;
SELECT MAX(salary) AS highest_salary FROM employees;
What is the result of the following SQL query? SELECT department, COUNT(*) FROM employees GROUP BY department HAVING COUNT(*) > 5;
Returns an error because HAVING cannot be used with COUNT(*).
Returns the count of all departments with exactly 5 employees.
Counts all employees in the database.
Counts employees in each department and returns only departments with more than 5 employees.
Which SQL statement correctly finds the average price of all products in the products table, excluding any rows where the price column is NULL?
SELECT AVG(price) WHERE price IS NOT NULL FROM products;
SELECT AVG(price) FROM products WHERE price IS NOT NULL;
SELECT AVG(price) FROM products;
SELECT AVG(price) FROM products WHERE price IS NULL;
What does a table contain data about?
A specific relation
A specific entity type
A specific key
A specific attribute
How is a table characterized?
By nodes and edges
By rows and columns
By attributes and entities
By keys and values
What does a column in a relational model represent?
A collection of tables
A primary key
A unique identifier for each row
A specific attribute of the table's entity type
What restricts the set of values allowed in a column?
Foreign key
Domain
Index
Primary key
How are tables in a relational database linked to each other?
By using foreign keys only
Through relationships
By using primary keys only
By using indexes
What is a potential issue with storing all information in a single table?
It would require less maintenance
It would contain duplicate data
It would be easy to update
It would be very efficient
What is one consequence of redundancy in a database system?
Reduced maintenance effort
Slower system performance
Easier data updates
Faster system performance
What is the first step in the normalization process?
Achieving First Normal Form (1NF)
Achieving Fourth Normal Form (4NF)
Achieving Second Normal Form (2NF)
Achieving Third Normal Form (3NF)
What is the main goal of removing repeating groups in a database table?
To allow data duplication
To achieve first normal form
To add more columns
To create unnormalized tables
What does the acronym DML stand for?
a) Data Modeling Language
b) Data Markup Language
c) Data Management Language
d) Data Manipulation Language
Which SQL statement is used to add new rows to a table?
a) CREATE
b) DELETE
c) UPDATE
d) INSERT
What happens if the number of columns listed in an INSERT statement does not match the number of values provided?
a) The database will assign default values
b) The values will be filled in randomly
c) The extra columns will be ignored
d) An error will occur
Which SQL statement is used to change the data within an existing row?
a) ALTER
b) DELETE
c) UPDATE
d) INSERT
In an INSERT INTO statement, which of the following is not a valid method of inserting rows?
a) ALTER
b) DELETE
c) UPDATE
d) INSERT
Which of the following allows you to remove rows from a table in SQL?
a) INSERT
b) SELECT
c) DELETE
d) UPDATE
What happens when you use the DELETE statement without a WHERE clause?
All rows are deleted
The command will produce an error
Only the first row is deleted
No rows are deleted
Which command is used to remove all data from a table without removing the table itself?
REMOVE
TRUNCATE
DROP
DELETE
In an UPDATE statement, what is the purpose of the WHERE clause?
To sort the data before updating
To limit the number of columns updated
To check for foreign key constraints
To specify which rows should be updated
Which of the following SQL statements is not used to modify data in a table?
SELECT
INSERT
UPDATE
DELETE
What happens if you try to insert a row with a foreign key that does not exist in the parent table?
The row will be inserted with a NULL value for the foreign key
The insertion will fail
The insertion will succeed, but with a warning
The row will be inserted, but the foreign key will be ignored
Which operator can be used in an UPDATE statement to update records based on a pattern match?
LIKE
IN
BETWEEN
OR
What SQL keyword is used to compare values in a range?
IN
LIMIT
LIKE
BETWEEN
In the SQL statement UPDATE superheroes SET age = 37 WHERE age BETWEEN 35 AND 38;, which records will be updated?
No records will be updated
Only records with age 35 and 38
All records with age 36
Records with ages 35, 36, 37, and 38
In the SQL statement DELETE FROM superheroes WHERE hero_id > 3;, what records will be deleted?
No records will be deleted
Records with hero_id greater than 3
All records
Only records with hero_id less than 3
Which SQL keyword is used to specify the table from which to retrieve data?
SELECT
FROM
JOIN
WHERE
What is the function of the SQL keyword 'SELECT'?
To modify data
To retrieve data
To delete data
To create a table
What does the comparison operator '=' mean?
Not equal to
Equal to
Greater than
Less than
Which operator means "greater than"?
>=
>
<
<=
In the SQL query, which table is being queried? SELECT * FROM customers WHERE contactLastName < 'C';
customers
orders
products
employees
Which of the following is a correct SQL statement to select all data from a table?
SELECT DATA FROM table_name;
SELECT * FROM table_name;
SELECT COLUMNS FROM table_name;
SELECT ALL FROM table_name;
In SQL, what does the statement "SELECT * FROM customers" do?
Deletes all data from the customers table
Selects all columns from the customers table
Selects specific columns from the customers table
Updates all data in the customers table
In the SQL query, what does the asterisk (*) represent?
Select all columns
Select all rows
Select a specific column
Select a specific row
What is the function of the SQL statement: SELECT * FROM customers WHERE contactLastName LIKE '%sh'?
Selects customers with last names starting with 'sh'
Selects customers with last names exactly 'sh'
Selects customers with last names containing 'sh'
Selects customers with last names ending with 'sh'
What is the result of using the OR condition with both conditions true?
The record is deleted
The record is not selected
The record is selected
The record is updated
AND and OR both require all conditions to be true.
AND and OR both require all conditions to be true
AND requires both conditions to be true, OR requires at least one
AND requires at least one condition to be true, OR requires both
AND and OR both require at least one condition to be true
What is the effect of the condition MSRP < 100 in a SQL query?
It selects records with MSRP equal to 100.
It selects records with MSRP not equal to 100.
It selects records with MSRP greater than 100.
It selects records with MSRP less than 100.
What is the primary use of the IN condition in SQL?
To delete records from a table
To update records in a table
To check if a value is within a specified list
To sort records in a table
What is the primary purpose of a relational database?
To replicate data across tables
To establish relationships between tables
To increase redundancy
To store data as plain text
Which SQL command is used to create a table?
INSERT
DROP TABLE
CREATE TABLE
SELECT
What does the AUTO_INCREMENT attribute do?
Automatically increments a primary key value
Automatically updates a row
Automatically joins two tables
Automatically creates a table
Which join type retrieves only rows with matching conditions in both tables?
INNER JOIN
LEFT JOIN
RIGHT JOIN
FULL OUTER JOIN
What is a Cartesian Product in SQL?
The result of a SELECT query
A type of indexing
The combination of a LEFT and RIGHT JOIN
The result of a JOIN without a WHERE clause
What does a FOREIGN KEY in one table refer to?
A secondary key in another table
A primary key in another table
An index in another database
A column in the same table
Which SQL clause specifies the condition for joining two tables?
USING
ON
WHERE
JOIN
What is the purpose of table aliases in SQL?
To rename tables permanently
To delete tables
To change table data types
To temporarily assign alternate names to tables
Which of the following does NOT return rows with NULL values in join conditions?
RIGHT JOIN
INNER JOIN
LEFT JOIN
FULL OUTER JOIN
Which join includes all rows from the left table, even if there are no matches in the right table?
RIGHT OUTER JOIN
LEFT OUTER JOIN
FULL OUTER JOIN
INNER JOIN
Which SQL query retrieves all rows from the product table?
SELECT * FROM product;
SELECT supplier FROM product;
INSERT INTO product;
SELECT * FROM supplier;
What does the GROUP BY clause do in SQL?
Filters rows
Groups rows with the same values in specified columns
Joins two tables
Deletes duplicate rows
What type of join is used to find rows that have no matching values in the other table?
ANTI JOIN
INNER JOIN
CROSS JOIN
FULL OUTER JOIN
Which query lists the number of products each supplier provides?
SELECT supplier, COUNT(*) FROM products;
SELECT companyName, COUNT(productName) FROM suppliers;
SELECT COUNT(supplier) FROM product;
SELECT s.companyName, COUNT(p.productName) FROM suppliers AS s INNER JOIN products AS p ON s.SupplierID = p.SupplierID GROUP BY s.companyName;
Which of the following are types of SQL joins?
UNION
CROSS JOIN
OUTER JOIN
INNER JOIN
What are common issues with repeating data in databases?
Inconsistent data updates
Higher chances of errors
Easier data retrieval
Waste of storage space
What actions can the WHERE clause perform in SQL?
Exclude certain columns
Sort data
Specify join conditions
Filter rows
Which key is used to represent relationships between tables?
Primary key
Tertiary key
Foreign key
Secondary key
What is the relationship between tables in a database called?
Primary key relationship
Unique key relationship
Composite key relationship
Foreign key relationship
In the given SQL query, what is being selected? SELECT supplierID FROM products WHERE productName LIKE '%bread%';
productName
supplierID
productID
customerID
What is the purpose of the '%' symbol in the SQL query? SELECT supplierID FROM products WHERE productName LIKE '%bread%';
To represent a wildcard for any sequence of characters
To denote a comment
To indicate a table name
To specify a column name
What type of data is being queried in the example? SELECT * FROM suppliers
Products
Customers
Suppliers
Orders
What would be the result if the 'LIKE' clause was changed to 'NOT LIKE' in the query? SELECT DISTINCT supplierID FROM products WHERE productName LIKE '%bread%';
It would select products containing 'bread'
It would select all products
It would select products not containing 'bread'
It would cause an error
What does the SQL function MIN() return?
The minimum value in a column
The sum of values in a column
The average value in a column
The maximum value in a column
What SQL clause is used to exclude certain values in a query?
OMIT
EXCLUDE
NOT IN
IN
What does the SQL statement "SELECT * FROM products" do?
Deletes all products
Updates all products
Selects specific columns from the products table
Selects all columns from the products table
What does the "NOT IN" clause do in the SQL query?
Includes specified values
Deletes specified values
Updates specified values
Excludes specified values
What is a subquery in SQL?
A command that retrieves the primary key of a table
A standalone query unrelated to other queries
A query embedded within another SQL query
A filter that sorts data by date
What is the purpose of a foreign key in relational databases?
It uniquely identifies each row within a table
It acts as a substitute for the primary key
It is used only in subqueries
It establishes a relationship between two tables
