SQL MCQs – Introduction to Databases

Structured Query Language (SQL) is a powerful tool for managing and querying data in relational databases. It is used to perform operations like retrieving, inserting, updating, and deleting data. SQL is essential for backend developers, data analysts, and database administrators. Preparing with multiple-choice questions (MCQs) helps solidify these foundational concepts and improves problem-solving skills for interviews.

1.) What does SQL stand for?

A) Sequential Query Language
B) Structured Query Language
C) Simple Query Language
D) Standard Query Language

Answer: Option B

Explanation: SQL stands for Structured Query Language and is used to communicate with databases.

2.) Which of the following is a type of SQL statement?

A) Data Definition Language (DDL)
B) Data Manipulation Language (DML)
C) Data Control Language (DCL)
D) All of the above

Answer: Option D

Explanation: SQL statements are categorized into DDL, DML, and DCL based on their purpose.

3.) Which SQL command is used to retrieve data from a database?

A) INSERT
B) UPDATE
C) SELECT
D) DELETE

Answer: Option C

Explanation: The SELECT command is used to fetch data from a database.

4.) What is a primary key?

A) A unique identifier for a table record
B) A duplicate identifier for a table record
C) A command to fetch records
D) None of the above

Answer: Option A

Explanation: A primary key uniquely identifies each row in a table.

5.) Which command is used to delete all rows from a table without removing the table?

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

Answer: Option C

Explanation: The SQL TRUNCATE command is used to remove all the rows from the table without using conditions. The SQL DELETE command is used to remove one or multiple rows from a table using conditions.

6.) What is the purpose of the WHERE clause in SQL?

A) To sort data
B) To filter records
C) To join tables
D) To create indexes

Answer: Option B

Explanation: The WHERE clause filters records that meet specified conditions.

7.) Which SQL function is used to count the number of rows in a table?

A) COUNT()
B) SUM()
C) ROWCOUNT()
D) TOTAL()

Answer: Option A

Explanation: COUNT() returns the number of rows in a table or query result.

8.) What does the GROUP BY clause do?

A) Groups rows with the same values
B) Deletes duplicate rows
C) Sorts rows
D) Filters rows

Answer: Option A

Explanation: GROUP BY is used to arrange identical data into groups.

9.) What is a foreign key?

A) A unique identifier for a table
B) A key linking two tables
C) A backup key
D) None of the above

Answer: Option B

Explanation: A foreign key links one table to another, maintaining referential integrity.

10.) Which SQL keyword is used to sort the result set?

A) FILTER
B) SORT
C) GROUP BY
D) ORDER BY

Answer: Option D

Explanation: ORDER BY is used to sort query results in ascending or descending order.

Leave a Reply

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