Monday, January 20, 2025
HomeProgrammingSQL MCQ (Multiple Choice Questions)

SQL MCQ (Multiple Choice Questions)

Here are some SQL Multiple Choice Questions (MCQs) covering a variety of topics including basic SQL commands, joins, normalization, and advanced SQL concepts.

1. Which of the following SQL commands is used to retrieve data from a database?

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

Answer: A) SELECT

2. Which of the following statements is true about the SQL WHERE clause?

A) The WHERE clause filters records before grouping them.
B) The WHERE clause filters records after grouping them.
C) The WHERE clause is used to filter records that meet a certain condition.
D) The WHERE clause is used to sort records in ascending or descending order.

Answer: C) The WHERE clause is used to filter records that meet a certain condition.

3. What is the purpose of the SQL GROUP BY clause?

A) To group rows that have the same values into summary rows.
B) To order the results in ascending or descending order.
C) To filter records based on a specific condition.
D) To combine multiple tables based on a common column.

Answer: A) To group rows that have the same values into summary rows.

4. Which of the following is not a valid SQL join type?

A) INNER JOIN
B) OUTER JOIN
C) LEFT JOIN
D) RIGHT JOIN
E) ALL JOIN

Answer: E) ALL JOIN

5. What does the SQL ALTER statement do?

A) Deletes a database table.
B) Modifies an existing database object, such as a table.
C) Creates a new database object.
D) Selects records from a table.

See also  Which Version Of Python Do I Have Installed

Answer: B) Modifies an existing database object, such as a table.

6. Which of the following functions does NOT perform aggregation in SQL?

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

Answer: D) LOWER()

7. Which SQL clause is used to remove duplicate values from the result set?

A) REMOVE
B) DISTINCT
C) UNIQUE
D) DELETE

Answer: B) DISTINCT

8. Which SQL statement is used to delete all rows in a table without removing the table structure?

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

Answer: C) TRUNCATE

9. What will the following SQL query return?

SELECT COUNT(*) FROM employees WHERE salary > 50000;

A) The number of employees with salary greater than 50,000.
B) The total salary of employees greater than 50,000.
C) The list of employees with salary greater than 50,000.
D) The average salary of employees greater than 50,000.

Answer: A) The number of employees with salary greater than 50,000.

10. What does the HAVING clause do in SQL?

A) It limits the number of rows returned.
B) It filters records after aggregation is done.
C) It sorts the results of a query.
D) It groups rows in a table.

Answer: B) It filters records after aggregation is done.

11. Which of the following statements is used to remove a table from a database?

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

Answer: B) DROP

See also  Banking Application in Java

12. Which of the following data types is used to store a large amount of text data?

A) CHAR
B) TEXT
C) VARCHAR
D) INT

Answer: B) TEXT

13. Which of the following SQL clauses is used to sort the result set?

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

Answer: A) ORDER BY

14. What is the result of the following SQL query?

SELECT * FROM students WHERE name = 'John' AND age = 20;

A) It returns all students who are named ‘John’.
B) It returns all students aged 20.
C) It returns all students who are named ‘John’ and are aged 20.
D) It returns an error because of the syntax.

Answer: C) It returns all students who are named ‘John’ and are aged 20.

15. Which of the following is the correct SQL statement to create a new table?

A) CREATE TABLE table_name;
B) NEW TABLE table_name;
C) CREATE DATABASE table_name;
D) CREATE TABLE table_name (column1 datatype, column2 datatype);

Answer: D) CREATE TABLE table_name (column1 datatype, column2 datatype);

16. What does the SQL UNION operator do?

A) Combines results from two SELECT queries and removes duplicates.
B) Combines results from two SELECT queries and includes duplicates.
C) Joins two tables on a common column.
D) Sorts data from two SELECT queries.

Answer: A) Combines results from two SELECT queries and removes duplicates.

17. Which of the following is used to add new rows to a table?

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

See also  Sudo Command in Linux With Examples

Answer: A) INSERT

18. What is the primary difference between DELETE and TRUNCATE?

A) DELETE removes all rows, while TRUNCATE removes specific rows based on conditions.
B) TRUNCATE is faster than DELETE for large tables because it doesn’t log individual row deletions.
C) DELETE cannot be rolled back, while TRUNCATE can be.
D) DELETE works on tables, while TRUNCATE works on databases.

Answer: B) TRUNCATE is faster than DELETE for large tables because it doesn’t log individual row deletions.

19. Which of the following SQL functions can be used to find the highest value in a column?

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

Answer: A) MAX()

20. Which of the following is true about SQL NULL values?

A) NULL is the same as an empty string.
B) NULL represents the absence of a value.
C) NULL is equal to zero.
D) NULL can be used in arithmetic operations.

Answer: B) NULL represents the absence of a value.

These questions cover a range of topics in SQL, from basic commands to more advanced concepts. They can be useful for beginners as well as for those preparing for SQL-based certifications or interviews.

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x