Which SQL function is used to count the number of non-NULL values in a column?
a) SUM() b) COUNT() c) AVG() d) MIN()
Correct Answer: b) COUNT()
Explanation: The COUNT() function returns the number of non-NULL values in a specified column.
Question 22
Which clause is used to specify the conditions for updating rows in a table?
a) WHERE b) ORDER BY c) SET d) LIMIT
Correct Answer: a) WHERE
Explanation: The WHERE clause is used to specify the conditions that must be met for a row to be updated in a table.
Question 23
In SQL, what is the primary purpose of the SELECT statement?
a) To insert new data b) To retrieve data from a table c) To update existing data d) To delete data from a table
Correct Answer: b) To retrieve data from a table
Explanation: The SELECT statement is used to retrieve data from one or more tables in a database.
Question 24
Which SQL clause is used to specify the table from which data is being retrieved?
a) WHERE b) FROM c) HAVING d) ORDER BY
Correct Answer: b) FROM
Explanation: The FROM clause specifies the table(s) from which the data is being retrieved in a SQL query.
Question 25
Which SQL operator is used to combine two conditions that must both be true?
a) OR b) AND c) LIKE d) NOT
Correct Answer: b) AND
Explanation: The AND operator is used to combine two or more conditions in a SQL query, where all conditions must be true for the result to be returned.
Question 26
Which SQL keyword is used to assign an alias to a column in a SELECT query?
a) ALIAS b) AS c) BY d) WITH
Correct Answer: b) AS
Explanation: The AS keyword is used to assign an alias to a column or table, allowing for more readable result sets.
Question 27
In SQL, which function removes leading and trailing spaces from a string?
a) TRIM() b) SUBSTRING() c) LOWER() d) REPLACE()
Correct Answer: a) TRIM()
Explanation: The TRIM() function removes leading and trailing spaces from a string in SQL.
Question 28
Which type of key is made up of two or more columns that together uniquely identify a row?
a) Primary Key b) Composite Key c) Foreign Key d) Unique Key
Correct Answer: b) Composite Key
Explanation: A Composite Key consists of two or more columns that together uniquely identify each row in a table.
Question 29
Which clause in SQL is used to filter results before grouping them in a GROUP BY query?
a) HAVING b) WHERE c) LIMIT d) ORDER BY
Correct Answer: b) WHERE
Explanation: The WHERE clause filters rows before they are grouped in a GROUP BY query, applying conditions to individual rows.
Question 30
Which SQL command is used to permanently delete a table, including all its data and structure?
a) DROP TABLE b) DELETE c) TRUNCATE d) REMOVE TABLE
Correct Answer: a) DROP TABLE
Explanation: The DROP TABLE command is used to delete a table and all its data and structure permanently from the database.
Question 31
Which SQL keyword is used to add a new row to a table?
a) UPDATE b) INSERT c) ALTER d) SELECT
Correct Answer: b) INSERT
Explanation: The INSERT command adds a new row to a table, specifying the values to be added for each column.
Question 32
Which type of join in SQL returns all rows from both tables, filling in NULLs where there are no matches?
a) LEFT JOIN b) FULL JOIN c) INNER JOIN d) RIGHT JOIN
Correct Answer: b) FULL JOIN
Explanation: A FULL JOIN returns all rows from both the left and right tables, filling in NULL values where there is no match.
Question 33
Which SQL function returns the absolute value of a number?
a) ABS() b) SUM() c) AVG() d) MAX()
Correct Answer: a) ABS()
Explanation: The ABS() function returns the absolute (positive) value of a given number in SQL.
Question 34
What is the primary purpose of the CREATE INDEX command in SQL?
a) To create a new table b) To create a new user c) To speed up query performance d) To delete data from a table
Correct Answer: c) To speed up query performance
Explanation: The CREATE INDEX command is used to create an index on one or more columns of a table to improve query performance.
Question 35
Which SQL function is used to return the current system date and time?
a) CURDATE() b) NOW() c) DATE() d) GETDATE()
Correct Answer: b) NOW()
Explanation: The NOW() function returns the current date and time based on the system's clock in SQL.
Question 36
In SQL, which command is used to change the structure of an existing table?
a) CREATE TABLE b) UPDATE c) ALTER TABLE d) DELETE
Correct Answer: c) ALTER TABLE
Explanation: The ALTER TABLE command is used to modify the structure of an existing table, such as adding or dropping columns.
Question 37
Which SQL operator is used to match a pattern in a string using wildcards?
a) LIKE b) BETWEEN c) IN d) EXISTS
Correct Answer: a) LIKE
Explanation: The LIKE operator is used to match patterns in strings using wildcard characters, such as % and _.
Question 38
Which type of database constraint ensures that a value is unique across all rows in a table?
a) CHECK b) FOREIGN KEY c) UNIQUE d) PRIMARY KEY
Correct Answer: c) UNIQUE
Explanation: The UNIQUE constraint ensures that values in a column or set of columns are unique across all rows in a table.
Question 39
Which SQL keyword is used to retrieve data from a table?
a) INSERT b) UPDATE c) SELECT d) DELETE
Correct Answer: c) SELECT
Explanation: The SELECT keyword is used to retrieve data from one or more tables in a database.
Question 40
Which SQL clause is used to sort rows in ascending order by default?
a) ORDER BY b) GROUP BY c) WHERE d) HAVING
Correct Answer: a) ORDER BY
Explanation: The ORDER BY clause sorts rows in ascending order by default, unless the DESC keyword is used to specify descending order.