Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Database security refers to the practices, tools, and measures used to protect a database from unauthorized access, misuse, modification, or destruction of its data. It ensures the confidentiality, integrity, and availab…
s data, not executable code. - Example in MySQL (using PDO in PHP) $stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username AND password = :password'); $stmt->execute(['username' => $username, 'pass…
SQL Injection is a type of attack where an attacker inserts or manipulates malicious SQL code into a query, which can compromise the database. It usually happens when user input is improperly sanitized or validated. Prev…
fter the full backup until the specified point in time. SQL Server Example: RESTORE DATABASE MyDatabase FROM DISK = 'C:\Backups\MyDatabase.bak'; RESTORE LOG MyDatabase FROM DISK = 'C:\Backups\MyDatabase_log.trn' WITH STO…
Point-in-time recovery (PITR) allows you to restore a database to a specific moment in time, which can be crucial in scenarios where: Data corruption or accidental deletion occurs. You want to rollback to a specific mome…
Answer: Database scaling refers to increasing a database's ability to handle more workload—either by increasing the resources available to a single instance or distributing the load across multiple instances. What interv…
read replica is a copy of a database that is used to offload read-only queries from the primary database (master). It is particularly useful for handling high read traffic and improving database scalability. How it helps…
Database caching involves storing frequently accessed data in a faster storage layer (e.g., memory) so that future requests for the same data can be served more quickly, reducing the need to query the database repeatedly…
Query optimization is the process of improving the efficiency of SQL queries to reduce resource consumption and improve response time. The goal is to make sure that queries are executed using the most efficient execution…
Event sourcing is a pattern where the state of an application is determined by a sequence of events, rather than storing the current state directly in the database. How it works: Instead of storing the current state of a…
materialized view is a database object that stores the results of a query physically, unlike regular view, which computes its result dynamically. Advantages: Faster query response times as the results are precomputed and…
time-series database (TSDB) is optimized for storing, querying, and managing time-stamped data (data associated with timestamps), often used for tracking events or metrics over time. Use cases: IoT data, server logs, sto…
Sharding is the process of breaking a large database into smaller, more manageable pieces (shards), each of which is stored on a different server. When to use it: When a single database server can no longer handle the vo…
Answer: The DISTINCT keyword is used to return only unique values in the result set, removing any duplicate rows. Example: SELECT DISTINCT Country FROM Customers; This will return a list of unique countries from the Cust…
The UNION operator combines the result sets of two or more SELECT queries into a single result set and removes duplicate records. All SELECT queries must have the same number of columns with compatible data types. Exampl…
CHAR: A fixed-length string data type. It always reserves the same amount of space regardless of the string's length. Use case: When the length of the string is known and consistent. VARCHAR: A variable-length string dat…
The LIMIT clause is used to specify the number of records returned by a SELECT query. It is commonly used to restrict the number of rows, especially for pagination. Example: SELECT * FROM Employees LIMIT 5; This will ret…
NULL represents the absence of a value in a column. It is not the same as an empty string or zero. Handling NULL: To check for NULL, use IS NULL or IS NOT NULL. To handle NULL in queries, use COALESCE() (returns the firs…
nd does not log individual row deletions. Cannot be rolled back (in most databases). Resets auto-increment counters. DELETE: Deletes rows based on a condition, and can be rolled back (if using transactions). Slower compa…
TRUNCATE: Deletes all rows in a table, but the table structure remains. It is faster and does not log individual row deletions. Cannot be rolled back (in most databases). Resets auto-increment counters. DELETE: Deletes r…
n Index is a database object that speeds up the retrieval of rows from a table by creating a data structure (often a B-tree). Indexes improve the performance of SELECT queries but can slow down INSERT, UPDATE, and DELETE…
SQL & Databases SQL Server Tutorial · SQL
Database security refers to the practices, tools, and measures used to protect a database
from unauthorized access, misuse, modification, or destruction of its data. It ensures the
confidentiality, integrity, and availability (often referred to as the CIA triad) of the data stored
within the database.
Why it's important:
information, financial data).
users.
threats like ransomware or DDoS attacks.
SQL & Databases SQL Server Tutorial · SQL
s data, not executable code.
$stmt = $pdo->prepare('SELECT * FROM users WHERE username =
:username AND password = :password');
$stmt->execute(['username' => $username, 'password' => $password]);
lengths, and ranges.
input is properly escaped.
to perform their tasks.
ttacks.
SQL & Databases SQL Server Tutorial · SQL
SQL Injection is a type of attack where an attacker inserts or manipulates malicious SQL
code into a query, which can compromise the database. It usually happens when user input
is improperly sanitized or validated.
Prevention techniques:
Use Prepared Statements/Parameterized Queries: This ensures that user input is treated
as data, not executable code.
$stmt = $pdo->prepare('SELECT * FROM users WHERE username =
:username AND password = :password');
$stmt->execute(['username' => $username, 'password' => $password]);
lengths, and ranges.
input is properly escaped.
to perform their tasks.
attacks.
SQL & Databases SQL Server Tutorial · SQL
fter the full backup until the specified point in time.
SQL Server Example:
RESTORE DATABASE MyDatabase FROM DISK = 'C:\Backups\MyDatabase.bak';
RESTORE LOG MyDatabase FROM DISK = 'C:\Backups\MyDatabase_log.trn'
WITH STOPAT = '2023-09-14T15:30:00'; -- Restore up to a specific
time
PostgreSQL Example:
To enable point-in-time recovery, you need to restore a base backup, then use WAL
(Write-Ahead Logging) archives to apply changes until the desired point.
recovery_target_time.
SQL & Databases SQL Server Tutorial · SQL
Point-in-time recovery (PITR) allows you to restore a database to a specific moment in
time, which can be crucial in scenarios where:
How it works:
after the full backup until the specified point in time.
SQL Server Example:
RESTORE DATABASE MyDatabase FROM DISK = 'C:\Backups\MyDatabase.bak';
RESTORE LOG MyDatabase FROM DISK = 'C:\Backups\MyDatabase_log.trn'
WITH STOPAT = '2023-09-14T15:30:00'; -- Restore up to a specific
time
PostgreSQL Example:
To enable point-in-time recovery, you need to restore a base backup, then use WAL
(Write-Ahead Logging) archives to apply changes until the desired point.
recovery_target_time.
SQL & Databases SQL Server Tutorial · SQL
Answer: Database scaling refers to increasing a database's ability to handle more workload—either by increasing the resources available to a single instance or distributing the load across multiple instances.
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
read replica is a copy of a database that is used to offload read-only queries from the
primary database (master). It is particularly useful for handling high read traffic and
improving database scalability.
can focus on write operations, reducing the load on the master.
operations.
serve read-heavy queries, while writes are only made to the master database.
Note: Read replicas are usually asynchronous, meaning there can be a slight delay in
replication. For critical real-time reads, this might not be suitable.
SQL & Databases SQL Server Tutorial · SQL
Database caching involves storing frequently accessed data in a faster storage layer (e.g.,
memory) so that future requests for the same data can be served more quickly, reducing the
need to query the database repeatedly.
requested, the cache can provide instant access to commonly requested
data.
Redis or Memcached) makes it accessible in nanoseconds, compared to the
millisecond access time of traditional disk-based databases.
improving the overall user experience.
Example: Frequently accessed user profiles in a web application can be cached using
Redis, so that subsequent requests don't have to query the database again.
SQL & Databases SQL Server Tutorial · SQL
Query optimization is the process of improving the efficiency of SQL queries to reduce
resource consumption and improve response time. The goal is to make sure that queries are
executed using the most efficient execution plan possible.
operations, improving overall system performance.
resource contention in high-traffic applications.
selecting all columns.
replace subqueries with joins when possible.
vs. OUTER JOIN).
SQL & Databases SQL Server Tutorial · SQL
Event sourcing is a pattern where the state of an application is determined by a sequence
of events, rather than storing the current state directly in the database.
entity (event) is stored as an immutable event in an event store. The state can be
reconstructed by replaying the events.
requiring full audit logs, and systems that need to capture historical data changes.
SQL & Databases SQL Server Tutorial · SQL
materialized view is a database object that stores the results of a query physically, unlike
regular view, which computes its result dynamically.
keep the data up to date.
retrieve the precomputed values instead of performing costly aggregation on
the fly.
SQL & Databases SQL Server Tutorial · SQL
time-series database (TSDB) is optimized for storing, querying, and managing
time-stamped data (data associated with timestamps), often used for tracking events or
metrics over time.
etc.
particular hour or day).
SQL & Databases SQL Server Tutorial · SQL
Sharding is the process of breaking a large database into smaller, more manageable pieces
(shards), each of which is stored on a different server.
queries.
cost-effective or possible.
region, etc.).
or cluster.
Example: In an e-commerce platform, you could shard user data based on geographic
region. Users from the US might be stored in one shard, while users from Europe are stored
in another.
SQL & Databases SQL Server Tutorial · SQL
Answer: The DISTINCT keyword is used to return only unique values in the result set, removing any duplicate rows. Example: SELECT DISTINCT Country FROM Customers; This will return a list of unique countries from the Customers table.
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
The UNION operator combines the result sets of two or more SELECT queries into a single
result set and removes duplicate records. All SELECT queries must have the same number
of columns with compatible data types.
Example:
SELECT Name FROM Employees
UNION
SELECT Name FROM Customers;
SQL & Databases SQL Server Tutorial · SQL
regardless of the string's length.
to store the string.
Example:
CREATE TABLE Example (
fixed_char CHAR(10),
variable_char VARCHAR(10)
);
SQL & Databases SQL Server Tutorial · SQL
The LIMIT clause is used to specify the number of records returned by a SELECT query. It is
commonly used to restrict the number of rows, especially for pagination.
Example:
SELECT * FROM Employees LIMIT 5;
This will return only the first 5 rows from the Employees table.
SQL & Databases SQL Server Tutorial · SQL
NULL represents the absence of a value in a column. It is not the same as an empty string or
zero.
value) or IFNULL().
Example:
SELECT Name, IFNULL(Salary, 0) FROM Employees;
SQL & Databases SQL Server Tutorial · SQL
nd does not log individual row deletions.
transactions).
Example:
DELETE FROM Employees WHERE Age < 18; -- Deletes only specific rows
TRUNCATE TABLE Employees; -- Deletes all rows
SQL & Databases SQL Server Tutorial · SQL
and does not log individual row deletions.
transactions).
Example:
DELETE FROM Employees WHERE Age < 18; -- Deletes only specific rows
TRUNCATE TABLE Employees; -- Deletes all rows
SQL & Databases SQL Server Tutorial · SQL
n Index is a database object that speeds up the retrieval of rows from a table by creating a
data structure (often a B-tree). Indexes improve the performance of SELECT queries but can
slow down INSERT, UPDATE, and DELETE operations.
Example:
CREATE INDEX idx_employee_name ON Employees(Name);