1. Which SQL function is used to calculate the total number of rows in a table?
A. COUNT()
B. SUM()
C. AVG()
D. MAX()
Answer: A) COUNT()
Rationale: The COUNT() function is used to return the number of rows in a table
or a result set.
2. What is the purpose of the HAVING clause in SQL?
A. To filter records before grouping
B. To filter records after grouping
C. To limit the number of rows returned
D. To sort the result set
Answer: B) To filter records after grouping
,Rationale: The HAVING clause is used to filter groups of records created by the
GROUP BY clause, whereas the WHERE clause filters rows before grouping.
3. What is the difference between a JOIN and a UNION in SQL?
A. JOIN combines rows from two tables based on a related column; UNION
combines the result sets of two queries
B. JOIN combines columns from two tables; UNION combines rows from two
queries
C. JOIN creates a new table; UNION deletes duplicate rows
D. JOIN can only be used on primary keys; UNION can only be used on foreign
keys
Answer: A) JOIN combines rows from two tables based on a related column;
UNION combines the result sets of two queries
Rationale: A JOIN is used to combine rows from two or more tables based on a
related column, while UNION combines results from multiple queries into a single
result set.
4. Which SQL statement is used to remove a table from the database?
A. DELETE
, B. DROP
C. REMOVE
D. TRUNCATE
Answer: B) DROP
Rationale: The DROP command is used to completely remove a table from the
database, including its structure and data.
5. What is the primary purpose of an Entity-Relationship Diagram (ERD)?
A. To define the data types of fields in a database
B. To visually represent the structure of a database and relationships between
entities
C. To generate SQL queries
D. To store database configuration settings
Answer: B) To visually represent the structure of a database and relationships
between entities
Rationale: ERDs help to model the logical structure of a database, showing
entities, attributes, and the relationships between them.
A. COUNT()
B. SUM()
C. AVG()
D. MAX()
Answer: A) COUNT()
Rationale: The COUNT() function is used to return the number of rows in a table
or a result set.
2. What is the purpose of the HAVING clause in SQL?
A. To filter records before grouping
B. To filter records after grouping
C. To limit the number of rows returned
D. To sort the result set
Answer: B) To filter records after grouping
,Rationale: The HAVING clause is used to filter groups of records created by the
GROUP BY clause, whereas the WHERE clause filters rows before grouping.
3. What is the difference between a JOIN and a UNION in SQL?
A. JOIN combines rows from two tables based on a related column; UNION
combines the result sets of two queries
B. JOIN combines columns from two tables; UNION combines rows from two
queries
C. JOIN creates a new table; UNION deletes duplicate rows
D. JOIN can only be used on primary keys; UNION can only be used on foreign
keys
Answer: A) JOIN combines rows from two tables based on a related column;
UNION combines the result sets of two queries
Rationale: A JOIN is used to combine rows from two or more tables based on a
related column, while UNION combines results from multiple queries into a single
result set.
4. Which SQL statement is used to remove a table from the database?
A. DELETE
, B. DROP
C. REMOVE
D. TRUNCATE
Answer: B) DROP
Rationale: The DROP command is used to completely remove a table from the
database, including its structure and data.
5. What is the primary purpose of an Entity-Relationship Diagram (ERD)?
A. To define the data types of fields in a database
B. To visually represent the structure of a database and relationships between
entities
C. To generate SQL queries
D. To store database configuration settings
Answer: B) To visually represent the structure of a database and relationships
between entities
Rationale: ERDs help to model the logical structure of a database, showing
entities, attributes, and the relationships between them.