- web.groovymark@gmail.com
- October 28, 2024
Question 01
Which SQL statement is used to create a new index on a table?
a) NEW INDEX
b) CREATE INDEX
c) ADD INDEX
d) DEFINE INDEX
Correct Answer: b) CREATE INDEX
Explanation: The CREATE INDEX statement is used to create an index on one or more columns of a table to improve query performance.
Question 02
What is the purpose of the ALTER TABLE statement in SQL?
a) To delete a table
b) To create a new table
c) To modify an existing table’s structure
d) To insert data into a table
Correct Answer: c) To modify an existing table's structure
Explanation: The ALTER TABLE statement is used to change the structure of an existing table, such as adding or dropping columns.
Question 03
Which SQL function is used to return the number of rows that meet a specified condition?
a) SUM()
b) COUNT()
c) TOTAL()
d) AVG()
Correct Answer: b) COUNT()
Explanation: The COUNT() function counts the number of rows that satisfy a given condition in a SQL query.
Question 04
Which SQL clause is used to sort the result set of a query in descending order?
a) ORDER BY DESC
b) SORT BY
c) GROUP BY
d) ORDER DESC
Correct Answer: a) ORDER BY DESC
Explanation: The ORDER BY clause with DESC sorts the result set in descending order based on the specified column(s).
Question 05
What does the acronym SQL stand for?
a) Structured Query Language
b) Simple Query Language
c) Standard Query Language
d) Secure Query Language
Correct Answer: a) Structured Query Language
Explanation: SQL stands for Structured Query Language, which is used for managing and manipulating relational databases.
Question 06
Which SQL statement is used to remove all records from a table without removing the table structure?
a) DELETE
b) TRUNCATE
c) DROP TABLE
d) CLEAR TABLE
Correct Answer: b) TRUNCATE
Explanation: The TRUNCATE command deletes all rows from a table while keeping the table structure intact for future use.
Question 07
Which SQL keyword is used to specify conditions for a query?
a) FILTER
b) WHERE
c) HAVING
d) LIMIT
Correct Answer: b) WHERE
Explanation: The WHERE clause is used to specify conditions that filter which rows are returned by a query.
Question 08
Which SQL function is used to find the highest value in a column?
a) MIN()
b) MAX()
c) SUM()
d) AVERAGE()
Correct Answer: b) MAX()
Explanation: The MAX() function returns the maximum value from a specified column in a table.
Question 09
What does the DISTINCT keyword do in a SQL query?
a) Removes duplicates from the result set
b) Sorts the result set
c) Limits the number of rows returned
d) Joins two tables
Correct Answer: a) Removes duplicates from the result set
Explanation: The DISTINCT keyword is used to ensure that the result set contains only unique records, eliminating duplicates.
Question 10
Which SQL command is used to delete a database?
a) DROP DATABASE
b) DELETE DATABASE
c) REMOVE DATABASE
d) TRUNCATE DATABASE
Correct Answer: a) DROP DATABASE
Explanation: The DROP DATABASE command is used to permanently remove a database and all its tables from the database management system.
Question 11
What is a foreign key in a relational database?
a) A unique identifier for each record
b) A reference to a primary key in another table
c) A key that allows duplicate values
d) A special type of index
Correct Answer: b) A reference to a primary key in another table
Explanation: A foreign key is a column or group of columns that establishes a link between two tables, referencing the primary key of another table.
Question 12
Which SQL function can be used to concatenate two strings?
a) COMBINE()
b) JOIN()
c) CONCAT()
d) MERGE()
Correct Answer: c) CONCAT()
Explanation: The CONCAT() function is used to join two or more strings together in SQL.
Question 13
Which SQL clause is used to specify the table from which to retrieve data?
a) FROM
b) WHERE
c) SELECT
d) ORDER BY
Correct Answer: a) FROM
Explanation: The FROM clause indicates the table(s) from which data will be retrieved in a SQL query.
Question 14
Which SQL function returns the current date without the time portion?
a) NOW()
b) CURDATE()
c) GETDATE()
d) DATE()
Correct Answer: b) CURDATE()
Explanation: The CURDATE() function returns the current date, excluding the time portion.
Question 15
Which SQL command is used to change the data type of an existing column?
a) CHANGE COLUMN
b) MODIFY COLUMN
c) ALTER COLUMN
d) UPDATE COLUMN
Correct Answer: c) ALTER COLUMN
Explanation: The ALTER TABLE command is used with the ALTER COLUMN clause to change the data type of an existing column.
Question 16
Which SQL statement is used to retrieve unique values from a column?
a) UNIQUE SELECT
b) SELECT DISTINCT
c) SELECT UNIQUE
d) DISTINCT SELECT
Correct Answer: b) SELECT DISTINCT
Explanation: The SELECT DISTINCT statement retrieves unique values from a specified column, removing duplicates.
Question 17
Which SQL command is used to assign privileges to a user?
a) GRANT
b) ASSIGN
c) ALLOW
d) PROVIDE
Correct Answer: a) GRANT
Explanation: The GRANT command is used to assign specific privileges to a user or role in the database.
Question 18
What does the SQL command DELETE do?
a) Removes a table from the database
b) Removes specific rows from a table
c) Clears all data from a table
d) Alters a table’s structure
Correct Answer: b) Removes specific rows from a table
Explanation: The DELETE command is used to remove specific rows from a table based on specified conditions.
Question 19
In SQL, which function calculates the average of a numeric column?
a) AVERAGE()
b) AVG()
c) MEAN()
d) TOTAL()
Correct Answer: b) AVG()
Explanation: The AVG() function computes the average value of a specified numeric column in SQL.
Question 20
Which clause is used in SQL to group rows that have the same values in specified columns?
a) ORDER BY
b) GROUP BY
c) HAVING
d) WHERE
Correct Answer: b) GROUP BY
Explanation: The GROUP BY clause groups rows that share the same values in specified columns, allowing for aggregate functions to be applied.