0
0
SQLquery~20 mins

Why databases over files in SQL - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Database Mastery: Why Databases Over Files
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why choose databases instead of plain files?

Which of the following is a key advantage of using a database over simple file storage?

ADatabases allow multiple users to access and modify data safely at the same time.
BFiles automatically organize data into tables without extra setup.
CFiles provide built-in data validation and indexing by default.
DDatabases store data only as plain text without structure.
Attempts:
2 left
💡 Hint

Think about what happens when many people want to use the data at once.

🧠 Conceptual
intermediate
2:00remaining
Data retrieval speed: databases vs files

Why are databases generally faster than files when searching for specific data?

ADatabases use indexes to quickly find data without scanning everything.
BFiles store data in memory for instant access.
CFiles automatically sort data to speed up searches.
DDatabases store data as plain text making it faster to read.
Attempts:
2 left
💡 Hint

Think about how you find a word in a dictionary quickly.

query_result
advanced
2:00remaining
What is the output of this SQL query on a file-based table?

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?

SQL
SELECT department, COUNT(*) AS count FROM employees GROUP BY department;
A[{"department": "Sales"}, {"department": "HR"}]
B[{"department": "Sales", "count": "5"}, {"department": "HR", "count": "3"}]
C[{"department": "Sales", "count": 5}, {"department": "HR", "count": 3}]
DSyntaxError: GROUP BY clause missing
Attempts:
2 left
💡 Hint

COUNT(*) returns a number, not a string. GROUP BY groups rows by department.

schema
advanced
2:00remaining
Which schema design supports data integrity better?

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.

AOption 1 because files are simpler and less prone to errors.
BOption 2 because relational tables enforce relationships and prevent invalid data.
COption 1 because files can be edited easily with any text editor.
DOption 2 because it stores all data in one big table without relations.
Attempts:
2 left
💡 Hint

Think about how to avoid mistakes like orders without customers.

optimization
expert
2:00remaining
Which SQL query optimizes data retrieval best for large datasets?

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;
ARuns fastest because it sums all amounts without grouping.
BRuns fastest because it groups all rows by region without extra filtering or sorting.
CRuns fastest because ordering helps the database optimize grouping.
DRuns fastest because it filters out zero amounts before grouping.
Attempts:
2 left
💡 Hint

Filtering data before grouping can reduce the amount of data processed.