50 multiple-choice questions with answers and detailed explanations. Untimed — choose an answer to check it instantly.
0/50 answered0 correct
Question 1 of 50
In SQL, which keyword is used to retrieve all columns from a table?
Correct answer: A) SELECT *
Explanation: The SELECT * statement is used to retrieve all columns from a table. SELECT DISTINCT eliminates duplicates, while SELECT ALL and SELECT COLUMNS are not valid SQL statements for this purpose.
Question 2 of 50
What is the function of the DELETE statement in SQL?
Correct answer: B) Deletes specific rows from a table
Explanation: The DELETE statement is used to remove specific rows from a table based on a condition. DROP is used to delete an entire table or database, and ALTER modifies the structure of a table.
Question 3 of 50
In relational algebra, what is the PROJECT operation used for?
Correct answer: C) To select specific columns from a table
Explanation: The PROJECT operation in relational algebra is used to select specific columns from a table, eliminating the others. SELECT chooses rows, while JOIN combines rows from two tables.
Question 4 of 50
Which SQL clause is used to group the result set by one or more columns?
Correct answer: A) GROUP BY
Explanation: The GROUP BY clause is used to group the result set by one or more columns, often in conjunction with aggregate functions. ORDER BY sorts the result, WHERE filters rows, and HAVING filters groups after aggregation.
Question 5 of 50
What is the purpose of a FOREIGN KEY in SQL?
Correct answer: B) To link rows between two tables
Explanation: A FOREIGN KEY is used to link rows between two tables by referencing a primary key in another table. It does not ensure uniqueness or speed up retrieval.
Question 6 of 50
What does the TRUNCATE statement do in SQL?
Correct answer: B) Deletes all rows from a table but retains the structure
Explanation: The TRUNCATE statement removes all rows from a table, but the table structure remains intact. DELETE can remove specific rows, and DROP deletes the entire table.
Question 7 of 50
Which SQL function is used to concatenate two or more strings?
Correct answer: A) CONCAT()
Explanation: The CONCAT() function is used to concatenate two or more strings in SQL. SUBSTRING() extracts part of a string, LENGTH() returns the length of a string, and TRIM() removes leading and trailing spaces.
Question 8 of 50
In relational algebra, which operation returns all rows from two tables, including rows that appear in both tables?
Correct answer: B) UNION
Explanation: The UNION operation returns all rows from two tables, including rows that appear in both tables. INTERSECT returns only rows common to both tables, JOIN combines rows based on a condition, and PRODUCT returns all possible combinations of rows from two tables.
Question 9 of 50
Which SQL clause is used to filter the result set based on a specified condition?
Correct answer: A) WHERE
Explanation: The WHERE clause is used to filter rows based on a specified condition. GROUP BY groups rows, ORDER BY sorts rows, and DISTINCT removes duplicates from the result set.
Question 10 of 50
Which SQL function is used to round a number to a specified number of decimal places?
Correct answer: C) ROUND()
Explanation: The ROUND() function is used to round a number to a specified number of decimal places. POW() raises a number to a power, SQRT() returns the square root, and ABS() returns the absolute value.
Question 11 of 50
What is the purpose of the HAVING clause in SQL?
Correct answer: B) To filter groups after aggregation
Explanation: The HAVING clause is used to filter groups of rows after aggregation, often used with GROUP BY. WHERE filters rows before aggregation, ORDER BY sorts rows, and DISTINCT removes duplicates.
Question 12 of 50
In SQL, what does the LIMIT clause do?
Correct answer: B) Limits the number of rows returned
Explanation: The LIMIT clause is used to specify the maximum number of rows to return in a result set. It does not limit columns, tables, or conditions.
Question 13 of 50
Which SQL function returns the length of a string?
Correct answer: B) LENGTH()
Explanation: The LENGTH() function returns the number of characters in a string. CONCAT() joins strings, TRIM() removes spaces, and SUBSTRING() extracts part of a string.
Question 14 of 50
In SQL, which type of join returns all rows from both tables, with NULLs for non-matching rows?
Correct answer: D) FULL JOIN
Explanation: A FULL JOIN returns all rows from both tables, with NULLs for non-matching rows. INNER JOIN returns only matching rows, while LEFT JOIN and RIGHT JOIN return all rows from one table and matching rows from the other.
Question 15 of 50
What does the EXISTS operator do in SQL?
Correct answer: B) Checks if a subquery returns any rows
Explanation: The EXISTS operator returns TRUE if a subquery returns one or more rows. It is often used to check for the existence of certain records within a subquery.
Question 16 of 50
What is the purpose of the UNION operator in SQL?
Correct answer: C) To combine the result sets of two queries, removing duplicates
Explanation: The UNION operator combines the result sets of two queries and removes any duplicate rows. If duplicates should be included, the UNION ALL operator is used.
Question 17 of 50
In SQL, which clause is used to sort the result set in descending order?
Correct answer: C) ORDER BY DESC
Explanation: The ORDER BY DESC clause is used to sort the result set in descending order. GROUP BY groups rows, WHERE filters rows, and DISTINCT removes duplicates.
Question 18 of 50
What is the purpose of a PRIMARY KEY in a relational database?
Correct answer: B) To uniquely identify each row in a table
Explanation: A PRIMARY KEY uniquely identifies each row in a table and ensures that no duplicate values exist. It is used to maintain data integrity.
Question 19 of 50
Which SQL clause is used to group rows that share the same values?
Correct answer: A) GROUP BY
Explanation: The GROUP BY clause groups rows that have the same values in specified columns, often used with aggregate functions. ORDER BY sorts rows, WHERE filters rows, and HAVING filters groups after aggregation.
Question 20 of 50
In SQL, what does the BETWEEN operator do?
Correct answer: B) Selects rows within a specified range of values
Explanation: The BETWEEN operator selects rows with values within a specified range, including the boundary values. It is commonly used with numeric or date values.
Question 21 of 50
What does the SUBSTRING() function do in SQL?
Correct answer: A) Extracts a portion of a string
Explanation: The SUBSTRING() function extracts a portion of a string, starting from a specified position and for a specified length. CONCAT() joins strings, LENGTH() returns the length of a string, and TRIM() removes spaces.
Question 22 of 50
Which SQL operator is used to check if a value matches a specified pattern?
Correct answer: C) LIKE
Explanation: The LIKE operator is used to check if a value matches a specified pattern, often using wildcards such as % or _. BETWEEN selects values within a range, IN checks if a value is in a list, and EXISTS checks if a subquery returns rows.
Question 23 of 50
What is a self join in SQL?
Correct answer: B) A join between a table and itself
Explanation: A self join occurs when a table is joined with itself to compare rows within the same table. It is useful for hierarchical data or comparisons between rows.
Question 24 of 50
Which SQL keyword is used to rename a column or table in a query result?
Correct answer: D) AS
Explanation: The AS keyword is used to rename a column or table in a query result. FROM specifies the table, and RENAME is used to change the name of a table or column but not in a query result.
Question 25 of 50
Which of the following SQL statements is used to grant user privileges?
Correct answer: C) GRANT
Explanation: The GRANT statement is used to assign specific privileges to users, such as SELECT, INSERT, or DELETE. REVOKE is used to remove those privileges, while ALTER modifies database objects, and INSERT adds new data.
Question 26 of 50
What is the purpose of a JOIN in SQL?
Correct answer: B) To combine rows from multiple tables based on related columns
Explanation: The JOIN clause is used to combine rows from two or more tables based on a related column. It does not remove rows, create new tables, or retrieve unique rows.
Question 27 of 50
Which SQL function is used to return the remainder of a division?
Correct answer: B) MOD()
Explanation: The MOD() function returns the remainder of a division. It is useful for checking divisibility or cycling through values. POW() raises a number to a power, SQRT() returns the square root, and ROUND() rounds a number.
Question 28 of 50
In SQL, what does the DISTINCT keyword do?
Correct answer: B) Removes duplicate rows from the result set
Explanation: The DISTINCT keyword removes duplicate rows from the result set, ensuring that only unique rows are returned. It does not affect sorting or joining tables.
Question 29 of 50
Which SQL operator is used to combine rows from two or more tables without any conditions?
Correct answer: B) CROSS JOIN
Explanation: A CROSS JOIN combines all rows from two tables without any conditions, resulting in the Cartesian product of the tables. It does not match rows based on a condition, unlike INNER JOIN, LEFT JOIN, or RIGHT JOIN.
Question 30 of 50
What is the purpose of the ALTER statement in SQL?
Correct answer: B) To modify the structure of an existing table
Explanation: The ALTER statement is used to modify the structure of an existing table, such as adding or removing columns. INSERT adds rows, DELETE removes rows, and CREATE creates new databases or tables.
Question 31 of 50
In SQL, what is a subquery?
Correct answer: A) A query that is nested inside another query
Explanation: A subquery is a query that is nested inside another query, typically within the WHERE, FROM, or SELECT clauses. It is used to perform additional filtering or calculations within the main query.
Question 32 of 50
Which SQL function is used to calculate the natural logarithm of a number?
Correct answer: A) LOG()
Explanation: The LOG() function returns the natural logarithm of a number. POW() raises a number to a power, SQRT() returns the square root, and ABS() returns the absolute value.
Question 33 of 50
Which SQL function is used to remove leading and trailing spaces from a string?
Correct answer: C) TRIM()
Explanation: The TRIM() function removes leading and trailing spaces from a string. CONCAT() joins strings, SUBSTRING() extracts part of a string, and LENGTH() returns the number of characters in a string.
Question 34 of 50
What does the LEFT JOIN do in SQL?
Correct answer: B) Returns all rows from the left table and the matching rows from the right table
Explanation: A LEFT JOIN returns all rows from the left table and the matching rows from the right table. If there is no match, NULL values are returned for columns from the right table.
Question 35 of 50
Which SQL function is used to return the current date and time?
Correct answer: B) NOW()
Explanation: The NOW() function returns the current date and time. CURDATE() returns only the current date, DATE() extracts the date part from a timestamp, and TIME() extracts the time part.
Question 36 of 50
Which SQL clause is used to return rows that match a specific condition after aggregation?
Correct answer: B) HAVING
Explanation: The HAVING clause is used to filter rows after aggregation, typically used with GROUP BY. WHERE filters rows before aggregation, while ORDER BY sorts the result set.
Question 37 of 50
In SQL, which type of join returns only rows that have matching values in both tables?
Correct answer: C) INNER JOIN
Explanation: An INNER JOIN returns only rows that have matching values in both tables. LEFT JOIN and FULL JOIN include non-matching rows, while CROSS JOIN returns the Cartesian product of both tables.
Question 38 of 50
What does the POW() function do in SQL?
Correct answer: C) Raises a number to the power of another number
Explanation: The POW() function raises a number to the power of another number. LOG() calculates the natural logarithm, ROUND() rounds a number, and ABS() returns the absolute value.
Question 39 of 50
Which SQL operator is used to check if a value is within a list of values?
Correct answer: C) IN
Explanation: The IN operator checks if a value is within a specified list of values. LIKE is used for pattern matching, BETWEEN selects values within a range, and EXISTS checks for the existence of rows in a subquery.
Question 40 of 50
In SQL, what is the purpose of the CREATE VIEW statement?
Correct answer: B) To create a virtual table based on a query
Explanation: The CREATE VIEW statement creates a virtual table (view) based on the result of a query. It does not store data but provides a way to simplify complex queries.
Question 41 of 50
Which SQL function is used to return the square root of a number?
Correct answer: B) SQRT()
Explanation: The SQRT() function returns the square root of a number. ROUND() rounds a number, POW() raises a number to a power, and LOG() calculates the natural logarithm.
Question 42 of 50
What is a PRIMARY INDEX in a relational database?
Correct answer: B) An index on the primary key column of a table
Explanation: A PRIMARY INDEX is an index on the primary key column of a table, used to improve query performance. It is not automatically created and does not enforce referential integrity or contain unique values unless specified.
Question 43 of 50
Which SQL function is used to concatenate multiple values into a single string?
Correct answer: A) CONCAT()
Explanation: The CONCAT() function is used to concatenate multiple values into a single string. SUBSTRING() extracts a portion of a string, LENGTH() returns the length of a string, and TRIM() removes spaces.
Question 44 of 50
In SQL, which function is used to find the maximum value in a column?
Correct answer: A) MAX()
Explanation: The MAX() function returns the maximum value in a column. MIN() returns the minimum value, COUNT() returns the number of rows, and AVG() returns the average value.
Question 45 of 50
What is the purpose of a FOREIGN KEY in SQL?
Correct answer: B) To link rows between two tables
Explanation: A FOREIGN KEY links rows between two tables by referencing a primary key in another table. It is used to maintain relationships between tables.
Question 46 of 50
Which SQL clause is used to filter rows based on an aggregate function?
Correct answer: B) HAVING
Explanation: The HAVING clause filters rows based on the result of an aggregate function, such as SUM() or COUNT(). WHERE filters rows before aggregation, while GROUP BY groups rows and ORDER BY sorts them.
Question 47 of 50
Which SQL statement is used to remove a column from an existing table?
Correct answer: B) ALTER TABLE
Explanation: The ALTER TABLE statement is used to modify the structure of an existing table, including adding or removing columns. DROP COLUMN is not a valid standalone command, and TRUNCATE removes rows but retains the table structure.
Question 48 of 50
What does the COUNT() function return in SQL?
Correct answer: B) The number of rows in a result set
Explanation: The COUNT() function returns the number of rows in a result set. SUM() adds numeric values, AVG() calculates the average, and MAX() returns the highest value in a column.
Question 49 of 50
Which SQL clause is used to filter rows based on a specific condition?
Correct answer: A) WHERE
Explanation: The WHERE clause is used to filter rows based on a specific condition. It is commonly used before the rows are grouped or sorted by GROUP BY or ORDER BY.
Question 50 of 50
What is the function of the AVG() aggregate function in SQL?
Correct answer: A) To calculate the average value of a column
Explanation: The AVG() function calculates the average value of a column. MAX() returns the highest value, COUNT() returns the number of rows, and SUM() adds up numeric values.
Set 3 complete
You scored 0%
0 correct out of 0 answered (50 questions in this set).