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
What does the GROUP BY clause do in SQL?
Correct answer: B) Groups rows that share the same values in specified columns
Explanation: The GROUP BY clause is used to group rows that have the same values in specified columns. It is often used with aggregate functions like SUM(), COUNT(), or AVG().
Question 2 of 50
Which SQL operator is used to combine two result sets and return only the rows that are common between them?
Correct answer: B) INTERSECT
Explanation: The INTERSECT operator returns only the rows that are common between two result sets. UNION combines all rows and removes duplicates, while JOIN and CROSS JOIN combine rows from multiple tables.
Question 3 of 50
In a relational database, what is the primary role of a PRIMARY KEY?
Correct answer: A) To enforce unique values in a column
Explanation: A PRIMARY KEY uniquely identifies each row in a table and ensures that no duplicate values exist. It is critical for maintaining data integrity in a relational database.
Question 4 of 50
What does the UNION ALL operator do in SQL?
Correct answer: B) Combines rows from two result sets and includes duplicates
Explanation: The UNION ALL operator combines rows from two result sets without removing duplicates. If duplicates should be removed, the UNION operator is used.
Question 5 of 50
Which SQL function is used to return the number of characters in a string?
Correct answer: A) LENGTH()
Explanation: The LENGTH() function returns the number of characters in a string. CONCAT() is used to join strings, SUBSTRING() extracts a portion of a string, and TRIM() removes leading and trailing spaces.
Question 6 of 50
What is the purpose of the DELETE statement in SQL?
Correct answer: B) To delete specific rows from a table
Explanation: The DELETE statement is used to remove specific rows from a table based on a condition. It does not delete the table itself or the entire database.
Question 7 of 50
In SQL, which 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. SQRT() returns the square root, ABS() returns the absolute value, and MOD() returns the remainder of a division.
Question 8 of 50
Which SQL clause is used to filter rows after they have been grouped?
Correct answer: C) HAVING
Explanation: The HAVING clause is used to filter rows after they have been grouped, often used with the GROUP BY clause. WHERE filters rows before aggregation, while ORDER BY sorts rows and LIMIT restricts the number of rows returned.
Question 9 of 50
What is the purpose of the ROLLBACK command in SQL?
Correct answer: B) To revert changes made during a transaction
Explanation: The ROLLBACK command is used to undo changes made during a transaction, restoring the database to its previous state. COMMIT saves changes, and DELETE and ALTER perform specific modifications on data.
Question 10 of 50
In SQL, what is a view?
Correct answer: B) A virtual table based on the result of a query
Explanation: A view is a virtual table in SQL that is created based on the result of a query. It does not store data itself but retrieves data from the underlying tables.
Question 11 of 50
Which SQL function returns the square root of a number?
Correct answer: B) SQRT()
Explanation: The SQRT() function returns the square root of a number. POW() raises a number to a power, LOG() returns the natural logarithm, and ROUND() rounds a number to a specified number of decimal places.
Question 12 of 50
What is the purpose of the ALTER TABLE statement in SQL?
Correct answer: B) To modify the structure of an existing table
Explanation: The ALTER TABLE statement is used to modify the structure of an existing table, such as adding or removing columns. It does not insert rows or delete rows from the table.
Question 13 of 50
Which SQL function is used to calculate the total of numeric values in a column?
Correct answer: B) SUM()
Explanation: The SUM() function is used to calculate the total of all numeric values in a column. AVG() calculates the average, COUNT() returns the number of rows, and MAX() returns the highest value.
Question 14 of 50
What is the function of the TRIM() function in SQL?
Correct answer: B) To remove leading and trailing spaces from a string
Explanation: The TRIM() function removes leading and trailing spaces from a string. LENGTH() returns the number of characters in a string, CONCAT() joins strings, and SUBSTRING() extracts a portion of a string.
Question 15 of 50
In SQL, which operator is used to check if a value exists in a list of values?
Correct answer: A) IN
Explanation: The IN operator is used to check if a value exists in a list of values. LIKE is used for pattern matching, EXISTS checks if a subquery returns any rows, and BETWEEN selects values within a range.
Question 16 of 50
In SQL, which function is used to concatenate two or more strings?
Correct answer: C) CONCAT()
Explanation: The CONCAT() function is used to join two or more strings together. LENGTH() returns the number of characters in a string, TRIM() removes spaces, and SUBSTRING() extracts part of a string.
Question 17 of 50
In SQL, what is the purpose of the EXISTS operator?
Correct answer: B) To check if a subquery returns one or more rows
Explanation: The EXISTS operator returns TRUE if a subquery returns one or more rows. It is commonly used to check for the presence of records that match certain criteria.
Question 18 of 50
In SQL, what does the BETWEEN operator do?
Correct answer: A) Selects values within a specific range
Explanation: The BETWEEN operator is used to select values that fall within a specific range, including the boundary values. It is often used with numeric or date values.
Question 19 of 50
In SQL, what does the LEFT JOIN do?
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 20 of 50
Which SQL function is used to return the current time?
Correct answer: B) TIME()
Explanation: The TIME() function returns the current time. CURDATE() returns the current date, NOW() returns both the current date and time, and DATE() is used to extract the date portion from a timestamp.
Question 21 of 50
In SQL, what is the purpose of the HAVING clause?
Correct answer: B) To filter rows after aggregation
Explanation: The HAVING clause is used to filter rows after aggregation, often used with GROUP BY. It is similar to the WHERE clause but specifically used with aggregated data.
Question 22 of 50
In SQL, what is the purpose of the ORDER BY clause?
Correct answer: B) To sort rows in ascending or descending order
Explanation: The ORDER BY clause is used to sort rows in ascending or descending order based on one or more columns. By default, it sorts in ascending order unless DESC is specified.
Question 23 of 50
What is a foreign key in a relational database?
Correct answer: B) A field that links two tables by referencing the primary key of another table
Explanation: A foreign key is a column or group of columns that links two tables by referencing the primary key in another table, ensuring referential integrity between them.
Question 24 of 50
Which SQL operator is used to return rows that do not match a pattern?
Correct answer: C) NOT LIKE
Explanation: The NOT LIKE operator is used to select rows that do not match a specified pattern. LIKE is used to match a pattern, while IN and BETWEEN check for values in a list or range, respectively.
Question 25 of 50
Which SQL function is used to calculate the average value of a column?
Correct answer: B) AVG()
Explanation: The AVG() function calculates the average value of numeric values in a column. SUM() adds values, COUNT() returns the number of rows, and MAX() returns the highest value in a column.
Question 26 of 50
In SQL, what is a CROSS JOIN?
Correct answer: B) A join that returns all rows from both tables, regardless of match
Explanation: A CROSS JOIN returns the Cartesian product of two tables, meaning it returns all combinations of rows from both tables. It does not require matching values between the tables.
Question 27 of 50
In SQL, which function is used to extract the year from a date?
Correct answer: A) YEAR()
Explanation: The YEAR() function extracts the year from a date. DATE() is used to format a date, NOW() returns the current date and time, and EXTRACT() can also extract specific parts of a date.
Question 28 of 50
Which SQL statement is used to remove a column from an existing table?
Correct answer: C) 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 part of the ALTER TABLE statement and not a standalone command.
Question 29 of 50
In SQL, what is the role of the COUNT() function?
Correct answer: B) To return the number of rows in a result set
Explanation: The COUNT() function returns the total number of rows in a result set. It is commonly used to count rows that meet a specific condition. SUM() adds values, MAX() returns the highest value, and AVG() calculates the average.
Question 30 of 50
In SQL, what does the EXISTS operator do?
Correct answer: A) Returns TRUE if a subquery returns any rows
Explanation: The EXISTS operator checks if a subquery returns any rows and returns TRUE if it does. It is used to verify the existence of records in a subquery.
Question 31 of 50
Which SQL keyword is used to create a new table in a database?
Correct answer: B) CREATE
Explanation: The CREATE keyword is used to create a new table in a database. ALTER modifies an existing table, INSERT adds new rows, and UPDATE modifies existing rows.
Question 32 of 50
Which SQL operator is used to select values within a range?
Correct answer: C) BETWEEN
Explanation: The BETWEEN operator is used to select values within a specified range, often with numeric or date values. It includes the boundary values in the result set.
Question 33 of 50
In SQL, which clause is used to sort rows in descending order?
Correct answer: C) ORDER BY DESC
Explanation: The ORDER BY DESC clause sorts the result set in descending order. WHERE filters rows, GROUP BY groups rows, and HAVING filters groups after aggregation.
Question 34 of 50
In SQL, what is the purpose of the DROP statement?
Correct answer: B) To remove a table or database
Explanation: The DROP statement is used to remove a table or database from the system entirely. DELETE removes rows from a table, ALTER modifies a table structure, and UPDATE changes data in existing rows.
Question 35 of 50
Which SQL function returns the remainder of a division operation?
Correct answer: B) MOD()
Explanation: The MOD() function returns the remainder of a division. It is commonly used to determine divisibility or perform calculations involving cyclic patterns.
Question 36 of 50
In SQL, what is the purpose of the JOIN clause?
Correct answer: C) To combine rows from two or more tables based on related columns
Explanation: The JOIN clause is used to combine rows from multiple tables based on related columns, typically a foreign key and a primary key. It does not insert data or sort the result set.
Question 37 of 50
In SQL, which keyword is used to modify the structure of an existing table?
Correct answer: A) ALTER
Explanation: The ALTER keyword is used to modify the structure of an existing table, such as adding or removing columns. INSERT adds data, CREATE creates new objects, and DROP removes objects.
Question 38 of 50
Which SQL function is used to return the current date and time?
Correct answer: C) NOW()
Explanation: The NOW() function returns the current date and time in SQL. CURDATE() returns only the current date, DATE() extracts the date portion from a timestamp, and TIME() returns the current time.
Question 39 of 50
In SQL, what is a self join?
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 within the same set of rows.
Question 40 of 50
Which SQL function is used to remove duplicate rows from a result set?
Correct answer: A) DISTINCT
Explanation: The DISTINCT function removes duplicate rows from a result set, ensuring that only unique rows are returned. GROUP BY groups rows, ORDER BY sorts rows, and HAVING filters groups after aggregation.
Question 41 of 50
What is the purpose of the INNER JOIN in SQL?
Correct answer: B) To return only the rows that match in both tables
Explanation: The INNER JOIN returns only the rows that have matching values in both tables. It does not include unmatched rows, which are handled by LEFT JOIN or RIGHT JOIN.
Question 42 of 50
In SQL, which clause is used to group rows that have the same values?
Correct answer: B) GROUP BY
Explanation: The GROUP BY clause is used to group rows that have the same values in specified columns. It is often used with aggregate functions like SUM(), COUNT(), or AVG().
Question 43 of 50
What is the purpose of the FOREIGN KEY in SQL?
Correct answer: B) To link rows between two tables based on related columns
Explanation: A FOREIGN KEY creates a relationship between two tables by linking a column in one table to a primary key in another table. It helps enforce referential integrity between the tables.
Question 44 of 50
In SQL, which operator is used to return rows that match a specific pattern?
Correct answer: D) LIKE
Explanation: The LIKE operator is used to return rows that match a specified pattern, often using wildcards such as % or _. It is commonly used for pattern matching in string columns.
Question 45 of 50
What is the function of the HAVING clause in SQL?
Correct answer: B) To filter groups after aggregation
Explanation: The HAVING clause filters groups after aggregation, typically used with the GROUP BY clause. It is similar to the WHERE clause but specifically used for aggregated data.
Question 46 of 50
In SQL, which function is used to return 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 SUM() adds numeric values.
Question 47 of 50
What is the purpose of the COMMIT statement in SQL?
Correct answer: B) To save changes made during a transaction
Explanation: The COMMIT statement saves the changes made during a transaction to the database. If the changes need to be undone, the ROLLBACK statement is used.
Question 48 of 50
Which SQL function is used to return the current date?
Correct answer: A) CURDATE()
Explanation: The CURDATE() function returns the current date in SQL. NOW() returns both the current date and time, TIME() returns only the time, and YEAR() extracts the year from a date.
Question 49 of 50
What does the TRUNCATE statement do in SQL?
Correct answer: B) Removes all rows from a table but keeps the table structure
Explanation: The TRUNCATE statement removes all rows from a table, but the table structure remains intact. It is faster than DELETE because it does not log individual row deletions.
Question 50 of 50
Which SQL operator is used to check if a value is NULL?
Correct answer: A) IS NULL
Explanation: The IS NULL operator is used to check if a value is NULL. IS NOT NULL checks for non-NULL values, while = NULL and != NULL are not valid for checking NULL values in SQL.
Set 5 complete
You scored 0%
0 correct out of 0 answered (50 questions in this set).