Which of the following is a key advantage of using a database over simple file storage?
Think about what happens when many people want to use the data at once.
Databases support concurrent access with safety mechanisms, unlike plain files which can get corrupted if multiple users write at the same time.
Why are databases generally faster than files when searching for specific data?
Think about how you find a word in a dictionary quickly.
Databases create indexes like a book's index, so they can jump directly to the needed data instead of reading everything.
Assume a table employees stored in a database and also exported as a CSV file. The SQL query below is run on the database:
SELECT department, COUNT(*) AS count FROM employees GROUP BY department;
What is the expected output?
SELECT department, COUNT(*) AS count FROM employees GROUP BY department;
COUNT(*) returns a number, not a string. GROUP BY groups rows by department.
The query counts employees per department and returns numeric counts, not strings. Option C matches this output.
Given two options for storing customer orders, which schema better ensures data integrity?
Option 1: Store all orders in a single file with no structure.
Option 2: Use a database with separate tables for customers and orders linked by customer ID.
Think about how to avoid mistakes like orders without customers.
Relational databases enforce foreign keys and constraints, preventing invalid data like orders linked to non-existent customers.
Consider a large sales table with millions of rows. Which query will run fastest to find total sales per region?
A) SELECT region, SUM(amount) FROM sales GROUP BY region;
B) SELECT region, SUM(amount) FROM sales WHERE amount > 0 GROUP BY region;
C) SELECT region, SUM(amount) FROM sales GROUP BY region ORDER BY region;
D) SELECT region, SUM(amount) FROM sales;
Filtering data before grouping can reduce the amount of data processed.
Filtering out zero amounts reduces rows to group, speeding up aggregation. Option D uses a WHERE clause to filter before grouping.