Full-Stack Development Full-Stack Development Backend Systems & API Design 2 — Questions and Answers
Question 1: What is the primary difference between SQL and NoSQL databases?
- SQL databases are faster; NoSQL databases are slower
- SQL databases use structured tables with schemas; NoSQL databases use flexible document or key-value models (Correct answer)
- SQL is open source; NoSQL is proprietary
- SQL runs on-premise; NoSQL runs only in the cloud
Correct answer: SQL databases use structured tables with schemas; NoSQL databases use flexible document or key-value models
SQL databases enforce a rigid schema with relational tables and ACID transactions, while NoSQL databases offer flexible schemas suited for hierarchical or unstructured data.
Question 2: In a relational database, what does a foreign key enforce?
- Uniqueness of values in a column
- Referential integrity by ensuring a value in one table matches an existing primary key in another (Correct answer)
- Encryption of sensitive fields
- Indexing for faster lookups
Correct answer: Referential integrity by ensuring a value in one table matches an existing primary key in another
A foreign key constraint ensures that a value in a child table's column must correspond to an existing row in the referenced parent table, maintaining referential integrity.
Question 3: What is an ORM (Object-Relational Mapper) used for in backend development?
- Converting JSON to XML
- Mapping database tables to programming language objects so developers can query the DB with code instead of raw SQL (Correct answer)
- Managing object memory allocation
- Optimizing relational queries at the database level
Correct answer: Mapping database tables to programming language objects so developers can query the DB with code instead of raw SQL
ORMs like Sequelize, Prisma, or TypeORM abstract database tables into classes/objects, letting developers perform CRUD operations using their language's syntax.
Question 4: What does database indexing primarily improve?
- Write performance for INSERT operations
- Read performance for query lookups on indexed columns (Correct answer)
- Storage efficiency by compressing rows
- Data integrity through constraint checking
Correct answer: Read performance for query lookups on indexed columns
An index creates a data structure that allows the database to find rows matching a WHERE clause without scanning the entire table, drastically speeding up reads.
Question 5: Which MongoDB query operator finds documents where a field's value is in a given array?
- $contains
- $in (Correct answer)
- $match
- $exists
Correct answer: $in
$in selects documents where the field value equals any value in the provided array, equivalent to SQL's IN clause.
Question 6: What is a database transaction and why is it important?
- A payment processing record linked to a database row
- A sequence of operations treated as a single atomic unit that either fully succeeds or fully rolls back (Correct answer)
- A scheduled query that runs at a set time
- A database backup triggered on every write
Correct answer: A sequence of operations treated as a single atomic unit that either fully succeeds or fully rolls back
A transaction groups multiple database operations into an atomic unit, ensuring that partial updates cannot leave data in an inconsistent state if a failure occurs.
What is the primary difference between SQL and NoSQL databases?