Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
nother table. This prevents invalid references from being made. Enforcing Referencing Integrity: Use foreign keys to create relationships between tables. Enforce actions like ON DELETE CASCADE, ON UPDATE CASCADE, or ON D…
Referential integrity ensures that relationships between tables are consistent. Specifically, it ensures that a foreign key in one table must match a primary key or a unique key in another table. This prevents invalid re…
Answer: Data redundancy occurs when the same piece of data is stored in multiple places, which can lead to inconsistencies and wasted storage. To avoid redundancy: What interviewers expect A clear definition tied to SQL…
composite key is a combination of two or more columns in a table that can uniquely identify each record in the table. It is used when a single column is not sufficient to uniquely identify a row. Composite Key: Consists…
How does it differ from a primary key? A composite key is a combination of two or more columns in a table that can uniquely identify each record in the table. It is used when a single column is not sufficient to uniquely…
n Entity-Relationship Diagram (ERD) is a graphical representation of entities and their relationships to each other within a database. It is used to visualize the structure of a database and how tables (entities) relate…
surrogate key is an artificial, system-generated key used to uniquely identify a record in a table. It has no business meaning and is typically a number (e.g., auto-incremented ID). Surrogate Key: No business meaning. Co…
How is it different from a natural key? A surrogate key is an artificial, system-generated key used to uniquely identify a record in a table. It has no business meaning and is typically a number (e.g., auto-incremented I…
Answer: pplication? Designing a database schema for a large e-commerce application involves careful consideration of data requirements, scalability, and normalization. Key entities and relationships to consider: What int…
Answer: Designing a database schema for a large e-commerce application involves careful consideration of data requirements, scalability, and normalization. Key entities and relationships to consider: What interviewers ex…
MongoDB is a NoSQL document-oriented database that stores data in flexible, semi-structured documents rather than in rows and columns like SQL databases. Unlike SQL databases, which rely on rigid schemas, MongoDB uses a…
dvantages: Scalability: MongoDB scales horizontally through sharding, which can handle large datasets across distributed clusters. Flexibility: Schema-less design allows for dynamic data models and easier iteration durin…
document in MongoDB is a record represented as a JSON-like object (BSON format) that contains field-value pairs. It can have a flexible structure, meaning each document in a collection may contain different fields and da…
How does it differ from rows in SQL databases? A document in MongoDB is a record represented as a JSON-like object (BSON format) that contains field-value pairs. It can have a flexible structure, meaning each document in…
Answer: Database: A container for collections. MongoDB allows you to have multiple databases within the same instance. Collection: A group of MongoDB documents. Collections are similar to tables in SQL but don’t have a f…
Create: db.collection.insertOne({ name: "Alice", age: 25 }); db.collection.insertMany([{ name: "Bob", age: 30 }, { name: "Charlie", age: 35 }]); Read: db.collection.find({ age: { $gt: 30 } }); db.collection.findOne({ nam…
mount of data the system needs to scan. MongoDB creates indexes on fields that are queried frequently. Differences from SQL indexes: MongoDB uses B-tree indexes (by default) but also supports other types like hashed inde…
How is it different from SQL indexes? Indexing in MongoDB is a mechanism to improve query performance by reducing the amount of data the system needs to scan. MongoDB creates indexes on fields that are queried frequently…
The $in operator is used to match values in a specified array. It checks if the value of a field is equal to any value in the provided array. Example: db.collection.find({ age: { $in: [25, 30, 35] } }); This query finds…
utomatically. Sharded Cluster: Used for horizontal scaling. It splits data across multiple servers (shards) based on a shard key. Each shard holds a portion of the data, and a mongos router directs queries to the correct…
Replica Set: A group of MongoDB servers that maintain the same data. It provides high availability and data redundancy by replicating data across multiple servers. If the primary server goes down, one of the secondaries…
find(): Returns a cursor to all documents that match the query. You can iterate over the results using .forEach() or convert them to an array with .toArray(). Example: db.collection.find({ age: { $gt: 30 } }); findOne():…
Answer: nd count occurrences { $sort: { count: -1 } } // Sort by count in descending order ]); What interviewers expect A clear definition tied to SQL in SQL & Databases projects Trade-offs (performance, maintainabil…
How do you use it? The Aggregation Framework in MongoDB is used to perform complex data processing tasks such as grouping, filtering, sorting, and reshaping documents. It uses a pipeline of stages to process documents: E…
Answer: You can use the updateOne(), updateMany(), or replaceOne() methods to update data. Example: db.collection.updateOne({ name: "Alice" }, { $set: { age: 27 } }); $set updates the value of a field. $inc increments a…
SQL & Databases SQL Server Tutorial · SQL
nother table. This prevents invalid references from being made.
ON DELETE RESTRICT to define how changes in parent tables affect related
child tables.
Example:
table. If you try to delete a customer that has associated orders, referential integrity
will prevent the delete unless actions like CASCADE are specified.
SQL & Databases SQL Server Tutorial · SQL
Referential integrity ensures that relationships between tables are consistent. Specifically,
it ensures that a foreign key in one table must match a primary key or a unique key in
another table. This prevents invalid references from being made.
ON DELETE RESTRICT to define how changes in parent tables affect related
child tables.
Example:
table. If you try to delete a customer that has associated orders, referential integrity
will prevent the delete unless actions like CASCADE are specified.
SQL & Databases SQL Server Tutorial · SQL
Answer: Data redundancy occurs when the same piece of data is stored in multiple places, which can lead to inconsistencies and wasted storage. To avoid redundancy:
In a production SQL & Databases application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
SQL & Databases SQL Server Tutorial · SQL
composite key is a combination of two or more columns in a table that can uniquely
identify each record in the table. It is used when a single column is not sufficient to uniquely
identify a row.
Example: A table storing student-course enrollments might use a composite key
consisting of StudentID and CourseID to uniquely identify each enrollment record.
uniquely identifies each record in a table. It can be a single column or a composite
of multiple columns, but it must be unique for each row.
SQL & Databases SQL Server Tutorial · SQL
How does it differ from a primary key?
A composite key is a combination of two or more columns in a table that can uniquely
identify each record in the table. It is used when a single column is not sufficient to uniquely
identify a row.
Example: A table storing student-course enrollments might use a composite key
consisting of StudentID and CourseID to uniquely identify each enrollment record.
uniquely identifies each record in a table. It can be a single column or a composite
of multiple columns, but it must be unique for each row.
SQL & Databases SQL Server Tutorial · SQL
n Entity-Relationship Diagram (ERD) is a graphical representation of entities and their
relationships to each other within a database. It is used to visualize the structure of a
database and how tables (entities) relate to one another.
ERDs help in the conceptual design phase of a database, outlining entities, relationships,
nd keys before implementation.
SQL & Databases SQL Server Tutorial · SQL
surrogate key is an artificial, system-generated key used to uniquely identify a record in a
table. It has no business meaning and is typically a number (e.g., auto-incremented ID).
identify records.
natural keys.
SQL & Databases SQL Server Tutorial · SQL
How is it different from a natural key?
A surrogate key is an artificial, system-generated key used to uniquely identify a record in a
table. It has no business meaning and is typically a number (e.g., auto-incremented ID).
identify records.
natural keys.
SQL & Databases SQL Server Tutorial · SQL
Answer: pplication? Designing a database schema for a large e-commerce application involves careful consideration of data requirements, scalability, and normalization. Key entities and relationships to consider:
In a production SQL & Databases application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
SQL & Databases SQL Server Tutorial · SQL
Answer: Designing a database schema for a large e-commerce application involves careful consideration of data requirements, scalability, and normalization. Key entities and relationships to consider:
In a production SQL & Databases application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
SQL & Databases SQL Server Tutorial · SQL
MongoDB is a NoSQL document-oriented database that stores data in flexible,
semi-structured documents rather than in rows and columns like SQL databases. Unlike
SQL databases, which rely on rigid schemas, MongoDB uses a schema-less approach
where each document can have different fields and structures.
Key differences:
transactions for consistency.
flexibility, scalability, and ease of replication but may sacrifice some consistency in
distributed environments.
SQL & Databases SQL Server Tutorial · SQL
dvantages:
datasets across distributed clusters.
during development.
tolerance.
Disadvantages:
suitable for all applications (though it supports ACID transactions in some cases).
transactions, working with them is more complex compared to SQL.
inconsistency if not properly managed.
SQL & Databases SQL Server Tutorial · SQL
document in MongoDB is a record represented as a JSON-like object (BSON format)
that contains field-value pairs. It can have a flexible structure, meaning each document in a
collection may contain different fields and data types.
Differences from SQL Rows:
document is more flexible and can vary in structure.
store complex, nested data structures (arrays, sub-documents).
SQL & Databases SQL Server Tutorial · SQL
How does it differ from rows in
SQL databases?
A document in MongoDB is a record represented as a JSON-like object (BSON format)
that contains field-value pairs. It can have a flexible structure, meaning each document in a
collection may contain different fields and data types.
Differences from SQL Rows:
a document is more flexible and can vary in structure.
store complex, nested data structures (arrays, sub-documents).
SQL & Databases SQL Server Tutorial · SQL
Answer: Database: A container for collections. MongoDB allows you to have multiple databases within the same instance. Collection: A group of MongoDB documents. Collections are similar to tables in SQL but don’t have a fixed schema.
In a production SQL & Databases application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
SQL & Databases SQL Server Tutorial · SQL
Create:
db.collection.insertOne({ name: "Alice", age: 25 });
db.collection.insertMany([{ name: "Bob", age: 30 }, { name:
"Charlie", age: 35 }]);
db.collection.find({ age: { $gt: 30 } });
db.collection.findOne({ name: "Alice" });
db.collection.updateOne({ name: "Alice" }, { $set: { age: 26 } });
db.collection.updateMany({ age: { $lt: 30 } }, { $set: { status:
"young" } });
db.collection.deleteOne({ name: "Alice" });
db.collection.deleteMany({ age: { $lt: 30 } });
SQL & Databases SQL Server Tutorial · SQL
mount of data the system needs to scan. MongoDB creates indexes on fields that are
queried frequently.
Differences from SQL indexes:
hashed indexes, geospatial indexes, and text indexes.
indexes can be dynamic, allowing indexing on any field within a document.
queries.
SQL & Databases SQL Server Tutorial · SQL
How is it different from SQL indexes?
Indexing in MongoDB is a mechanism to improve query performance by reducing the
amount of data the system needs to scan. MongoDB creates indexes on fields that are
queried frequently.
Differences from SQL indexes:
hashed indexes, geospatial indexes, and text indexes.
indexes can be dynamic, allowing indexing on any field within a document.
queries.
SQL & Databases SQL Server Tutorial · SQL
The $in operator is used to match values in a specified array. It checks if the value of a field
is equal to any value in the provided array.
Example:
db.collection.find({ age: { $in: [25, 30, 35] } });
This query finds all documents where the age field is 25, 30, or 35.
SQL & Databases SQL Server Tutorial · SQL
utomatically.
(shards) based on a shard key. Each shard holds a portion of the data, and a
mongos router directs queries to the correct shard. Sharding helps manage large
datasets by distributing the load.
SQL & Databases SQL Server Tutorial · SQL
high availability and data redundancy by replicating data across multiple servers. If
the primary server goes down, one of the secondaries can be promoted to primary
automatically.
(shards) based on a shard key. Each shard holds a portion of the data, and a
mongos router directs queries to the correct shard. Sharding helps manage large
datasets by distributing the load.
SQL & Databases SQL Server Tutorial · SQL
find(): Returns a cursor to all documents that match the query. You can iterate over the
results using .forEach() or convert them to an array with .toArray().
Example:
db.collection.find({ age: { $gt: 30 } });
found.
Example:
db.collection.findOne({ name: "Alice" });
SQL & Databases SQL Server Tutorial · SQL
Answer: nd count occurrences { $sort: { count: -1 } } // Sort by count in descending order ]);
In a production SQL & Databases application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
SQL & Databases SQL Server Tutorial · SQL
How do you use
it?
The Aggregation Framework in MongoDB is used to perform complex data processing
tasks such as grouping, filtering, sorting, and reshaping documents.
It uses a pipeline of stages to process documents:
Example:
db.collection.aggregate([
{ $match: { status: "active" } }, // Filter documents
{ $group: { _id: "$age", count: { $sum: 1 } } }, // Group by age
and count occurrences
{ $sort: { count: -1 } } // Sort by count in descending order
]);
SQL & Databases SQL Server Tutorial · SQL
Answer: You can use the updateOne(), updateMany(), or replaceOne() methods to update data. Example: db.collection.updateOne({ name: "Alice" }, { $set: { age: 27 } }); $set updates the value of a field. $inc increments a field's value.
In a production SQL & Databases application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.