Web Development Database Basics 4 — Questions and Answers
Question 1: What is the purpose of the GROUP BY clause in SQL?
- To sort rows in ascending order
- To filter rows before aggregation
- To combine rows with the same value into summary rows (Correct answer)
- To join two tables on a common column
Correct answer: To combine rows with the same value into summary rows
GROUP BY groups rows that share the same values in specified columns so aggregate functions can be applied to each group.
Question 2: Which NoSQL database type stores data as key-value pairs?
- Document store
- Column-family store
- Key-value store (Correct answer)
- Graph database
Correct answer: Key-value store
Key-value stores (like Redis) store data as pairs of unique keys and their associated values, optimized for fast lookups.
Question 3: What does 'atomicity' mean in a database transaction?
- Each operation runs in parallel
- The transaction either completes fully or not at all (Correct answer)
- Data is stored in the smallest possible unit
- Each user transaction is isolated from others
Correct answer: The transaction either completes fully or not at all
Atomicity guarantees that all operations within a transaction succeed together or are all rolled back if any step fails.
Question 4: What is a stored procedure in SQL?
- A backup copy of a database table
- A precompiled set of SQL statements stored and executed on the server (Correct answer)
- A type of constraint on a column
- A virtual table created from a query
Correct answer: A precompiled set of SQL statements stored and executed on the server
A stored procedure is a precompiled collection of SQL statements saved in the database that can be executed with a single call.
Question 5: Which SQL keyword eliminates duplicate rows from a result set?
- UNIQUE
- DISTINCT (Correct answer)
- FILTER
- EXCEPT
Correct answer: DISTINCT
SELECT DISTINCT removes duplicate rows from query results, returning only unique value combinations.
Question 6: What is database sharding?
- Splitting a database into smaller, faster pieces across multiple servers (Correct answer)
- Encrypting database backups for security
- Creating read-only replicas of a database
- Merging two databases into one
Correct answer: Splitting a database into smaller, faster pieces across multiple servers
Sharding horizontally partitions a database by distributing rows across multiple servers to improve scalability and performance.
Question 7: Which constraint ensures that a column's value must already exist as a primary key in another table?
- UNIQUE
- CHECK
- FOREIGN KEY (Correct answer)
- NOT NULL
Correct answer: FOREIGN KEY
A FOREIGN KEY constraint enforces referential integrity by requiring that the column's value matches a primary key in the referenced table.
What is the purpose of the GROUP BY clause in SQL?