SQL MCQs – Introduction to Databases

21.) What is the purpose of the UNION operator?

A) Combines results of two queries
B) Joins tables
C) Filters duplicate rows
D) Deletes records

Answer: Option A

Explanation: UNION combines the results of two queries, eliminating duplicates.

22.) Which SQL command removes a table from the database?

A) DELETE
B) TRUNCATE
C) DROP
D) REMOVE

Answer: Option C

Explanation: DROP deletes the table structure and its data.

23.) What does the LIKE operator do?

A) Matches a pattern in a string
B) Sorts data
C) Joins tables
D) Deletes records

Answer: Option A

Explanation: LIKE is used in WHERE clauses to match specific patterns.

24.) Which aggregate function calculates the sum of a column?

A) MAX()
B) AVG()
C) COUNT()
D) SUM()

Answer: Option D

Explanation: SUM() computes the total of numeric column values.

25.) What is a subquery?

A) A temporary table
B) A type of join
C) A query within another query
D) None of the above

Answer: Option C

Explanation: Subqueries are nested queries used in SELECT, INSERT, UPDATE, or DELETE.

26.) What is the maximum number of primary keys a table can have?

A) 1
B) 2
C) Unlimited
D) None

Answer: Option A

Explanation: A table can have only one primary key, which may consist of single or composite columns.

27.) Which function returns the current date in SQL?

A) GETDATE()
B) CURDATE()
C) NOW()
D) All of the above

Answer: Option D

Explanation: All these functions return the current date, depending on the database.

28.) What does the HAVING clause do?

A) Filters grouped data
B) Joins tables
C) Deletes grouped data
D) None of the above

Answer: Option A

Explanation: HAVING filters groups created by GROUP BY.

29.) Which SQL clause is used to set a condition on aggregated data?

A) WHERE
B) HAVING
C) GROUP BY
D) FILTER

Answer: Option B

Explanation: HAVING sets conditions on grouped data.

30.) What is a database index?

A) A pointer to data in a table
B) A duplicate of a table
C) A key for foreign table linking
D) None of the above

Answer: Option A

Explanation: Indexes speed up data retrieval by pointing to specific rows in a table.

Leave a Reply

Your email address will not be published. Required fields are marked *