-
web.groovymark@gmail.com
- November 7, 2024
Question 21
Which keyword is used to create a table in SQL?
a) CREATE TABLE
b) NEW TABLE
c) ADD TABLE
d) DEFINE TABLE
Correct Answer: a) CREATE TABLE
Explanation: The CREATE TABLE command is used to define a new table and its columns in the database.
Question 22
What does the DISTINCT keyword do in a SQL query?
a) Sorts the results
b) Groups similar records
c) Removes duplicate records
d) Limits the number of rows
Correct Answer: c) Removes duplicate records
Explanation: The DISTINCT keyword ensures that the result set contains only unique records, eliminating any duplicates.
Question 23
What is a primary key in a relational database?
a) A column that can contain duplicate values
b) A column that uniquely identifies each row in a table
c) A foreign key referencing another table
d) A key that cannot be NULL
Correct Answer: b) A column that uniquely identifies each row in a table
Explanation: A primary key is a unique identifier for each row in a table, ensuring that no two rows have the same value in the primary key column(s).
Question 24
Which SQL function is used to combine multiple string values into a single string?
a) JOIN()
b) MERGE()
c) CONCAT()
d) COMBINE()
Correct Answer: c) CONCAT()
Explanation: The CONCAT() function combines two or more strings into one single string in SQL.
Question 25
Which SQL keyword is used to specify the conditions that must be true for records to be selected?
a) CONDITION
b) FILTER
c) WHERE
d) HAVING
Correct Answer: c) WHERE
Explanation: The WHERE clause specifies the criteria that must be met for records to be included in the result set of a query.
Question 26
What is the purpose of the INSERT INTO statement in SQL?
a) To modify existing data
b) To add new rows to a table
c) To delete rows from a table
d) To create a new table
Correct Answer: b) To add new rows to a table
Explanation: The INSERT INTO statement is used to add new records to a specified table in the database.
Question 27
Which SQL command is used to commit a transaction?
a) COMMIT
b) SAVE
c) FINALIZE
d) APPROVE
Correct Answer: a) COMMIT
Explanation: The COMMIT command is used to save all changes made during the current transaction to the database permanently.
Question 28
What does the IS NULL condition do in a SQL query?
a) Checks if a value is zero
b) Checks if a value is an empty string
c) Checks if a value is missing or undefined
d) Checks if a value is valid
Correct Answer: c) Checks if a value is missing or undefined
Explanation: The IS NULL condition checks whether a value in a column is NULL, indicating the absence of data.
Question 29
Which SQL statement is used to retrieve data from multiple tables?
a) SELECT MULTIPLE
b) SELECT ALL
c) SELECT JOIN
d) SELECT
Correct Answer: d) SELECT
Explanation: The SELECT statement retrieves data from one or more tables, and can be combined with JOIN clauses to access multiple tables.
Question 30
What is the purpose of the UNION operator in SQL?
a) To join two tables
b) To combine the results of two SELECT queries into one
c) To filter results
d) To sort results
Correct Answer: b) To combine the results of two SELECT queries into one
Explanation: The UNION operator is used to combine the result sets of two or more SELECT queries into a single result set, eliminating duplicates.
Question 31
Which SQL command is used to rename a column in a table?
a) RENAME COLUMN
b) ALTER COLUMN
c) CHANGE COLUMN
d) MODIFY COLUMN
Correct Answer: b) ALTER COLUMN
Explanation: The ALTER TABLE command with ALTER COLUMN is used to change the name of an existing column in a table.
Question 32
Which SQL function can be used to find the minimum value in a column?
a) LOWEST()
b) MIN()
c) SMALLEST()
d) FIRST()
Correct Answer: b) MIN()
Explanation: The MIN() function retrieves the smallest value from a specified column in SQL.
Question 33
Which SQL clause allows you to filter records based on aggregated values?
a) WHERE
b) HAVING
c) GROUP BY
d) FILTER
Correct Answer: b) HAVING
Explanation: The HAVING clause is used to filter groups of records based on conditions applied to aggregated values.
Question 34
What is the purpose of the DROP command in SQL?
a) To remove a record from a table
b) To delete an entire table or database
c) To modify a table’s structure
d) To update records in a table
Correct Answer: b) To delete an entire table or database
Explanation: The DROP command is used to permanently remove a table or database from the database management system.
Question 35
Which SQL command is used to create a new table with defined columns?
a) NEW TABLE
b) ADD TABLE
c) CREATE TABLE
d) DEFINE TABLE
Correct Answer: c) CREATE TABLE
Explanation: The CREATE TABLE command is used to define a new table along with its columns and data types.
Question 36
Which SQL function is used to count the number of rows that meet specific criteria?
a) SUM()
b) COUNT()
c) TOTAL()
d) NUMROWS()
Correct Answer: b) COUNT()
Explanation: The COUNT() function counts the number of rows that meet specified conditions in a SQL query.
Question 37
What does the TRUNCATE command do in SQL?
a) Deletes specific rows from a table
b) Deletes all rows from a table without logging individual row deletions
c) Removes the table structure
d) Modifies the structure of a table
Correct Answer: b) Deletes all rows from a table without logging individual row deletions
Explanation: The TRUNCATE command removes all rows from a table while preserving its structure, and it does not log individual row deletions.
Question 38
Which SQL function is used to calculate the total of a numeric column?
a) TOTAL()
b) SUM()
c) ADD()
d) COUNT()
Correct Answer: b) SUM()
Explanation: The SUM() function calculates the total of all values in a specified numeric column in SQL.
Question 39
Which SQL command would you use to update existing records in a table?
a) MODIFY
b) UPDATE
c) CHANGE
d) ALTER
Correct Answer: b) UPDATE
Explanation: The UPDATE command is used to modify existing records in a specified table.
Question 40
What does the IN operator do in a SQL query?
a) Checks for equality
b) Filters records based on multiple values
c) Joins two tables
d) Sorts results
Correct Answer: b) Filters records based on multiple values
Explanation: The IN operator is used to specify multiple values in a WHERE clause, allowing records to be filtered based on whether a column's value matches any value in the specified list.