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
Which SQL keyword is used to return only unique values from a column?
Correct answer: B) DISTINCT
Explanation: The DISTINCT keyword is used in SQL to return only unique values from a column, eliminating duplicates. UNIQUE is not a keyword for filtering query results, ALL returns all values including duplicates, and EXCEPT is used for set operations.
Question 2 of 50
In relational databases, what does the term "referential integrity" mean?
Correct answer: B) Foreign key values must either be NULL or match some primary key value
Explanation: Referential integrity ensures that foreign key values must either be NULL or match an existing value in the referenced primary key. It enforces the relationship between tables in a relational database.
Question 3 of 50
Which SQL clause is used to sort the rows in ascending order?
Correct answer: C) ORDER BY
Explanation: The ORDER BY clause is used to sort rows in ascending order by default, or descending order if DESC is specified. ORDER BY ASC is redundant, while SORT BY and ASCENDING are not valid SQL clauses.
Question 4 of 50
In SQL, which function is used to return the lowest value from a column?
Correct answer: A) MIN()
Explanation: The MIN() function returns the lowest value from a column. MAX() returns the highest value, AVG() calculates the average, and SUM() adds numeric values.
Question 5 of 50
What is a heap table in relational databases?
Correct answer: B) A table without any particular order imposed on rows
Explanation: A heap table is a table in which rows are stored without any specific order. It is commonly used in relational databases where the insertion order is not predefined.
Question 6 of 50
In SQL, what is the role of the MOD() function?
Correct answer: B) To return the remainder of a division
Explanation: The MOD() function returns the remainder of a division between two numbers. It is often used to determine if one number is divisible by another.
Question 7 of 50
In SQL, which operator is used to select rows that do not match a pattern?
Correct answer: B) NOT LIKE
Explanation: The NOT LIKE operator is used to select rows that do not match a specified pattern. LIKE selects rows that match a pattern, BETWEEN filters based on a range, and NOT IN checks for values not present in a list.
Question 8 of 50
In SQL, which clause is used to limit the number of rows returned by a query?
Correct answer: A) LIMIT
Explanation: The LIMIT clause restricts the number of rows returned by a query. WHERE filters rows, COUNT is an aggregate function that returns the number of rows, and HAVING filters groups after aggregation.
Question 9 of 50
What is the primary purpose of the INNER JOIN in SQL?
Correct answer: B) To return only matching rows from two tables
Explanation: An INNER JOIN returns only the rows that have matching values in both tables. It does not include unmatched rows, which are handled by LEFT, RIGHT, or FULL joins.
Question 10 of 50
In SQL, which function is used to calculate the total of values in a column?
Correct answer: C) 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 11 of 50
What is a non-clustered index in a relational database?
Correct answer: B) An index that improves search performance but does not alter the physical order of data
Explanation: A non-clustered index improves search performance by creating a separate structure to store index data, without altering the physical order of the rows in the table.
Question 12 of 50
In SQL, what does the JOIN clause do?
Correct answer: A) Combines rows from two or more tables based on related columns
Explanation: The JOIN clause is used to combine rows from two or more tables based on related columns, such as matching a foreign key to a primary key.
Question 13 of 50
In SQL, what does the UNION operator do?
Correct answer: B) Combines rows from two queries, removing duplicates
Explanation: The UNION operator combines the result sets of two queries and removes any duplicate rows. To keep duplicates, the UNION ALL operator is used.
Question 14 of 50
What is the purpose of the HAVING clause in SQL?
Correct answer: B) To filter rows after aggregation
Explanation: The HAVING clause is used to filter rows after aggregation, commonly used with aggregate functions such as SUM() or COUNT(). It is often paired with GROUP BY.
Question 15 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. POW() raises a number to a power, MOD() returns the remainder of a division, and LOG() calculates the natural logarithm.
Question 16 of 50
What is a full outer join in SQL?
Correct answer: B) A join that returns all rows from both tables, with NULLs for non-matching rows
Explanation: A full outer join returns all rows from both tables, with NULL values for columns where there is no match between the two tables.
Question 17 of 50
In SQL, what is the purpose of the INSERT statement?
Correct answer: B) To add new rows to a table
Explanation: The INSERT statement is used to add new rows to a table. UPDATE modifies existing data, DELETE removes rows, and SELECT is used to query data.
Question 18 of 50
What is the role of the FOREIGN KEY in a relational database?
Correct answer: B) To link rows between two tables based on a related column
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 related data.
Question 19 of 50
In SQL, which function is used to extract a portion of a string?
Correct answer: B) SUBSTRING()
Explanation: The SUBSTRING() function extracts a portion of a string based on the specified starting position and length. CONCAT() joins strings, LENGTH() returns the length of a string, and TRIM() removes leading and trailing spaces.
Question 20 of 50
In SQL, which command is used to delete a table from a database?
Correct answer: B) DROP
Explanation: The DROP command is used to remove a table from a database completely. DELETE removes rows from a table, TRUNCATE deletes all rows but keeps the table structure, and ALTER modifies the structure of an existing table.
Question 21 of 50
Which SQL function returns the number of rows that match a specified condition?
Correct answer: A) COUNT()
Explanation: The COUNT() function returns the number of rows that match a specified condition. SUM() adds values, MAX() returns the highest value, and AVG() calculates the average.
Question 22 of 50
What is a hash table in a relational database?
Correct answer: B) A table where rows are assigned to buckets based on a hash function
Explanation: A hash table assigns rows to buckets based on a hash function, which is used to improve query performance by quickly locating rows based on the hash key.
Question 23 of 50
In SQL, which clause is used to remove duplicate rows from the result set?
Correct answer: B) DISTINCT
Explanation: The DISTINCT clause removes duplicate rows from the result set. GROUP BY groups rows by specified columns, HAVING filters groups after aggregation, and LIMIT restricts the number of rows returned.
Question 24 of 50
What is a sorted table in a relational database?
Correct answer: B) A table where the rows are physically ordered by a specific column
Explanation: A sorted table has its rows physically ordered based on a specific column, usually the primary key. This can improve query performance for certain types of queries.
Question 25 of 50
In SQL, which clause is used to specify the condition for selecting rows?
Correct answer: B) WHERE
Explanation: The WHERE clause specifies the condition for selecting rows in a query. It is used to filter rows before they are returned by the query. SELECT retrieves data, FROM specifies the table, and ORDER BY sorts the result set.
Question 26 of 50
Which SQL function returns the absolute value of a number?
Correct answer: C) ABS()
Explanation: The ABS() function returns the absolute value of a number. ROUND() rounds a number, POW() raises a number to a power, and SQRT() returns the square root.
Question 27 of 50
What is the role of the GROUP BY clause in SQL?
Correct answer: B) To group rows that share the same values in specified columns
Explanation: The GROUP BY clause groups rows that have the same values in specified columns, often used with aggregate functions to summarize data. It does not sort rows or combine tables.
Question 28 of 50
In SQL, which keyword is used to rename a column in the result set?
Correct answer: A) AS
Explanation: The AS keyword is used to rename a column or table in the result set. RENAME is used to change the name of a table but not in a query result. SELECT is used to retrieve data.
Question 29 of 50
In SQL, which function is used to join two or more strings?
Correct answer: A) CONCAT()
Explanation: The CONCAT() function is used to join two or more strings together. LENGTH() returns the length of a string, TRIM() removes spaces, and SUBSTRING() extracts part of a string.
Question 30 of 50
What is the purpose of the ROLLBACK command in SQL?
Correct answer: C) To undo changes made during a transaction
Explanation: The ROLLBACK command undoes changes made during a transaction, returning the database to its previous state. COMMIT saves changes, and DROP deletes tables or databases.
Question 31 of 50
What is the default order of sorting when using the ORDER BY clause in SQL?
Correct answer: A) Ascending
Explanation: The default sorting order for the ORDER BY clause in SQL is ascending. If descending order is needed, the DESC keyword must be specified.
Question 32 of 50
In SQL, what type of join returns only the rows that match in both tables?
Correct answer: C) INNER JOIN
Explanation: An INNER JOIN returns only the rows that match in both tables. LEFT JOIN and FULL JOIN include unmatched rows, while CROSS JOIN returns the Cartesian product of both tables.
Question 33 of 50
In SQL, which function is used to calculate the natural logarithm of a number?
Correct answer: B) 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 34 of 50
In SQL, which function is used to remove leading and trailing spaces from a string?
Correct answer: B) TRIM()
Explanation: The TRIM() function removes leading and trailing spaces from a string. LENGTH() returns the length of a string, CONCAT() joins strings, and SUBSTRING() extracts part of a string.
Question 35 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 is used to check if a value is within a list of values. BETWEEN selects values within a range, LIKE is used for pattern matching, and EXISTS checks for the existence of rows in a subquery.
Question 36 of 50
In SQL, which keyword is used to combine two queries and include all duplicate rows?
Correct answer: B) UNION ALL
Explanation: The UNION ALL operator combines the result sets of two queries and includes all duplicate rows. UNION removes duplicates, INTERSECT returns common rows, and JOIN combines rows from different tables.
Question 37 of 50
What is the function of the COUNT() aggregate function in SQL?
Correct answer: A) To calculate the total number of rows in a result set
Explanation: The COUNT() function returns the total number of rows in a result set. AVG() calculates the average, MAX() returns the highest value, and SUM() adds up numeric values.
Question 38 of 50
In SQL, what does the EXISTS operator do?
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 used to check for the presence of records in a subquery.
Question 39 of 50
In SQL, which keyword is used to combine the result sets of two queries and remove duplicates?
Correct answer: B) UNION
Explanation: The UNION operator combines the result sets of two queries and removes duplicates. INTERSECT returns only the rows that are common to both queries, and UNION ALL combines the result sets without removing duplicates.
Question 40 of 50
In SQL, what does the HAVING clause do?
Correct answer: B) Filters groups after aggregation
Explanation: The HAVING clause filters groups of rows after they have been aggregated, typically used with GROUP BY. It is similar to the WHERE clause but used for aggregated data.
Question 41 of 50
Which SQL operator is used to select rows that match a specific pattern?
Correct answer: D) LIKE
Explanation: The LIKE operator is used to select rows that match a specified pattern, often using wildcards such as % or _. IN checks for values within a list, BETWEEN selects values within a range, and EXISTS checks for the existence of rows in a subquery.
Question 42 of 50
In SQL, which 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 DATE() extracts the date part from a timestamp.
Question 43 of 50
Which SQL statement is used to modify the structure of an existing table?
Correct answer: A) ALTER TABLE
Explanation: The ALTER TABLE statement is used to modify the structure of an existing table, such as adding, removing, or modifying columns. CREATE TABLE creates a new table, DELETE removes rows, and INSERT adds new rows.
Question 44 of 50
What does the DISTINCT keyword do in SQL?
Correct answer: B) Removes duplicate rows from the result set
Explanation: The DISTINCT keyword eliminates duplicate rows from the result set, ensuring that only unique rows are returned. It does not remove rows based on a condition or sort the result set.
Question 45 of 50
In SQL, which function is used to calculate the average of values in a column?
Correct answer: C) AVG()
Explanation: The AVG() function calculates the average of numeric values in a column. SUM() adds up the values, COUNT() returns the number of rows, and MAX() returns the highest value.
Question 46 of 50
Which SQL statement is used to add a new column to an existing table?
Correct answer: B) ALTER TABLE
Explanation: The ALTER TABLE statement is used to add a new column to an existing table. CREATE TABLE is used to create a new table, INSERT INTO adds new rows, and UPDATE modifies existing rows.
Question 47 of 50
In SQL, which clause is used to filter groups of rows after they have been aggregated?
Correct answer: B) HAVING
Explanation: The HAVING clause filters groups after they have been aggregated, typically used with GROUP BY. WHERE filters rows before aggregation, while ORDER BY sorts the result set and LIMIT restricts the number of rows returned.
Question 48 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 49 of 50
In SQL, which function is used to return the year from a date?
Correct answer: A) YEAR()
Explanation: The YEAR() function extracts the year from a date. CURDATE() returns the current date, DATE() formats a date, and EXTRACT() can be used to extract specific parts of a date, such as the year, month, or day.
Question 50 of 50
In SQL, what does the LEFT JOIN return?
Correct answer: B) 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.
Set 4 complete
You scored 0%
0 correct out of 0 answered (50 questions in this set).