SQL Interviw Quetions 2025
SQL Interviw Quetions 2025
"Hi, my name is [Your Name], and I have been working as a SQL Server Database
Administrator for the past five years. I started my career at [Previous Company], where I
managed a variety of SQL Server instances and databases, ranging from small
development environments to large production systems. I have a strong background in
database design, performance tuning, and troubleshooting. In my current role at
[Current Company], I lead a team of DBAs and have been instrumental in implementing
automated backup and maintenance solutions, which have significantly improved our
system reliability and performance. I am passionate about technology and always eager
to learn and adopt new tools and techniques to enhance our database operations."
"At my current company, we have a robust SQL Server environment with over 50
instances, including both on-premises and cloud-based solutions. We manage around
200 databases in total, with the largest database being approximately 5 terabytes in
size. This database is a critical OLTP system that supports our main e-commerce
platform, handling millions of transactions daily. We also have several smaller
databases for development, testing, and reporting purposes. Our environment is
designed to ensure high availability and disaster recovery, with regular monitoring and
maintenance schedules."
"When a major incident occurs, my first priority is to assess the impact and
communicate with the relevant stakeholders, including the development team, IT
management, and business leaders. I immediately gather all available information and
logs to diagnose the issue. If it's a critical system, I work with the team to implement a
temporary workaround to minimize downtime. Once the immediate issue is resolved, I
conduct a root cause analysis to understand what went wrong and how to prevent it
from happening again. I document the entire process and share the findings with the
team to ensure everyone is aware of the incident and the steps taken to resolve it."
5. Tell me something about the last issue you have faced and how did
you fix that?
"The last major issue I faced was a performance degradation in our primary OLTP
database. Users were experiencing slow query responses, which was affecting their
productivity. I started by analyzing the query execution plans and identifying the most
resource-intensive queries. I then optimized these queries by adding appropriate
indexes and rewriting some of the SQL code. Additionally, I reviewed the server
configuration and made adjustments to the memory and CPU settings. After
implementing these changes, the performance improved significantly, and user
complaints were reduced. I also set up a monitoring system to track the performance
metrics and ensure that the issue does not recur."
"If I encounter a database issue that I can't resolve, my next step would be to escalate
the issue to a more experienced colleague or a senior DBA. I would also reach out to the
SQL Server community, such as forums and user groups, to get insights and potential
solutions. If the issue is critical, I would contact Microsoft Support for assistance. In the
meantime, I would work with the development team to implement a temporary
workaround to keep the system operational. I would also document all the steps I have
taken and the information I have gathered to provide a clear picture of the issue to the
support team."
7. Explain any of your two deliveries or solutions for which you have
been recognized by your client and leaders?
"Sure, I'd like to share two projects that I am particularly proud of:
SQL Server Upgrade and Migrate Related Interview Question and Answer
• Upgrade: This involves moving SQL Server to a newer version, typically on the
same hardware. The database engine remains the same, but the version is
updated.
• Inventory: List all databases, linked servers, jobs, logins, SSIS packages, and
application connections.
• Compatibility Check: Identify any T-SQL syntax or features that are deprecated
in the target version.
3. What tools do you use to assess SQL Server before migration or upgrade?
• Data Migration Assistant (DMA): For compatibility and feature parity checks.
Upgrade Methods
• In-Place Upgrade:
o Downtime is required.
• Side-by-Side Upgrade:
o Lower risk.
• Jobs: Script out SQL Agent Jobs via SQL Server Management Studio (SSMS) or
export via PowerShell.
• Linked Servers: Script using SSMS or manually recreate them on the new server.
Migration Scenarios
• Migration Methods:
• Deprecated Feature Usage: Features that are no longer supported in the new
version.
• Logins and Orphaned Users: Ensuring that logins and users are correctly
mapped.
• SQL Agent Jobs Failing: Jobs may fail due to version-specific syntax changes.
Post-Migration/Upgrade Tasks
• Run Integrity Checks: Verify that jobs, linked servers, and other components are
functioning correctly.
Performance Considerations
11. Why should you not immediately change compatibility level after migration?
• Capture Performance Metrics: Monitor wait stats, query plans, CPU usage, and
other relevant metrics.
• Use Extended Events or Query Store: If supported, these tools can provide
detailed performance analysis.
• Keep the Source Server Online: Maintain the source server in read-only mode
until validation is complete.
• Have Backups and Scripts Ready: Prepare for reverse migration by having
backups and scripts ready to restore the old environment.
14. What’s the difference between migrating to Azure SQL Database vs Azure
SQL Managed Instance?
Bonus
15. What changes in SQL Server 2022 should be considered before upgrading?
• Azure Synapse Link: Integration with Azure Synapse for real-time analytics.
When patching a production SQL Server, it's essential to follow a structured and
cautious approach to minimize risks and ensure a smooth process. Here are the key
steps:
• Create a Full Database Backup: Before applying any patches, create a full
backup of all databases. This is crucial for recovery in case something goes
wrong during the patching process.
Testing:
Documentation:
• Document the Patching Process: Keep detailed records of the patches applied,
the SQL Server version, and any configuration changes made. This
documentation will be invaluable for troubleshooting and future reference.
2. Patch Application
Downloading Patches:
• Configure SQL Server Agent (if necessary): If your patching process involves
applying updates to SQL Server components, configure the SQL Server Agent to
handle these tasks. This can include scheduling the patch application or running
specific scripts.
Applying Patches:
• Follow the Instructions Provided: Use the SQL Server Configuration Manager or
other tools as specified in the patch documentation to apply the updates. Ensure
you follow the instructions carefully to avoid any errors.
• Restart SQL Server Services: After applying the patches, restart the SQL Server
services to activate the changes. This may include the SQL Server service, SQL
Server Agent, and any other related services.
• Run DBCC CHECKDB: After patching, verify the integrity of the databases by
running DBCC CHECKDB. This command helps ensure that the data is
consistent and there are no corruption issues.
Performance Monitoring:
Rollback Plan:
• Have a Rollback Plan: Prepare a rollback plan in case the patching process
causes problems or if the patches need to be reverted. This plan should include
steps to restore the full backup and revert any configuration changes.
Additional Considerations
Availability Groups:
• Patch Secondary Replicas First: If you are using Always On Availability Groups,
patch the secondary replicas before patching the primary replica. This ensures
that the primary replica can fail over to a patched secondary if needed.
Security:
• Address Known Vulnerabilities: Ensure that the patches you apply address any
known security vulnerabilities. Regularly check Microsoft's security bulletins and
advisories to stay informed.
Example Answer
"When patching a production SQL Server, I would start by creating a full database
backup to allow for a rollback if needed. I would then thoroughly test the patches in a
non-production environment to minimize the risk of issues in the production
environment. The patches would be applied using SQL Server Configuration Manager,
and the necessary services would be restarted. After patching, I would verify the
database consistency with DBCC CHECKDB and monitor server performance to ensure
that the patches didn't introduce any problems. Additionally, if using Always On
Availability Groups, I would patch the secondary replicas first. I would also ensure that
the patches address any known security vulnerabilities and have a detailed rollback
plan in place."
By following these steps, you can ensure that the patching process is as smooth and
risk-free as possible, maintaining the integrity and performance of your production SQL
Server.
What is JOIN in SQL, and what are the different types of joins?
JOIN is a SQL clause used to combine rows from two or more tables based on a related
column between them. It allows you to extract data from multiple tables in a single
query, making it a powerful tool for data analysis and reporting. SQL supports several
types of joins, each serving a different purpose:
o Definition: Returns only the rows that have matching values in both
tables.
o Syntax:
ON table1.common_column = table2.common_column;
o Example:
FROM Orders
ON Orders.CustomerID = Customers.CustomerID;
o Use Case: When you need to retrieve data that exists in both tables.
o Definition: Returns all rows from the left table, and the matched rows
from the right table. If there is no match, the result is NULL on the side of
the right table.
o Syntax:
ON table1.common_column = table2.common_column;
o Example:
FROM Orders
ON Orders.CustomerID = Customers.CustomerID;
o Use Case: When you need to retrieve all records from the left table and
the matching records from the right table, or NULL if there is no match.
o Definition: Returns all rows from the right table, and the matched rows
from the left table. If there is no match, the result is NULL on the side of
the left table.
o Syntax:
ON table1.common_column = table2.common_column;
o Example:
FROM Orders
ON Orders.CustomerID = Customers.CustomerID;
o Use Case: When you need to retrieve all records from the right table and
the matching records from the left table, or NULL if there is no match.
o Definition: Returns all rows when there is a match in either the left or the
right table. If there is no match, the result is NULL on the side of the table
that has no match.
o Syntax:
ON table1.common_column = table2.common_column;
o Example:
FROM Orders
ON Orders.CustomerID = Customers.CustomerID;
o Use Case: When you need to retrieve all records from both tables,
regardless of whether there is a match.
5. Cross Join:
o Syntax:
o Example:
FROM Orders
o Use Case: When you need to generate all possible combinations of rows
from the two tables.
o Definition: A table is joined with itself, often used to compare rows within
the same table.
o Syntax:
FROM table a
JOIN table b
ON a.common_column = b.common_column;
o Example:
FROM Employees a
JOIN Employees b
ON a.ManagerID = b.EmployeeID;
o Use Case: When you need to compare data within the same table, such
as employees and their managers.
Summary
• Inner Join: Returns rows that have matching values in both tables.
• Left Join: Returns all rows from the left table and the matched rows from the
right table.
• Right Join: Returns all rows from the right table and the matched rows from the
left table.
• Full Join: Returns all rows when there is a match in either table.
• Self Join: Joins a table with itself to compare rows within the same table.
SQL Server Mirroring and Log Shipping Interview Question and Answer
1. What is Mirroring?
Log Shipping is an automated process for backing up and restoring a database from
one server to another independent standby server. The primary server regularly backs
up its transaction logs and sends them to the secondary server, where they are
restored. This ensures that the secondary server has a copy of the database that is as
up-to-date as the last log backup. If the primary server fails, the secondary server can
be brought online with identical data, providing a recovery solution.
Key Differences
• Mirroring:
• Log Shipping:
Both solutions are useful for different scenarios, depending on the required level of
availability and the resources available for management.
Q1: Why do we need to establish a High Availability and Disaster Recovery Plan in
large companies?
Establishing a High Availability and Disaster Recovery (HA/DR) plan in large companies
is crucial to ensure that critical operational data and systems are available for the
longest possible time with the least possible downtime. This plan helps in:
• Compliance: Meeting regulatory and industry standards for data availability and
recovery.
Q2: List five of the High Availability and Disaster Recovery solutions that are
available in Microsoft SQL Server.
1. Log Shipping
2. Transactional Replication
3. Database Mirroring
Q3: What are the main differences between the SQL Server Always On Failover
Cluster and the SQL Server Always On Availability Groups?
• Resource Sharing:
o Always On Availability Groups: Each node has its own resources, with
no resource sharing concept.
• Read Operations:
• Configuration Level:
Q4: What are the differences between the SQL Server Database Mirroring and the
SQL Server Always On Availability Groups?
• Read Operations:
• Number of Replicas:
• Automatic Failover:
• Configuration Level:
Q5: How does the synchronization process work in the SQL Server Always On
Availability Groups between the different replicas?
• Primary to Secondary:
o The primary replica sends the transaction log records from the primary
database to the secondary replicas.
• Secondary Processing:
o At the secondary side, the transaction logs are written to the secondary
database transaction log file for caching, and then the transactions are
redone in the secondary database.
• Synchronization Modes:
An Availability Group is a group of databases hosted in a SQL Server instance called the
primary replica that is copied to and synchronized with up to eight servers, called
secondary replicas.
Q7: What are the availability modes used in the SQL Server Availability Group to
synchronize between the replicas?
1. Synchronous-Commit Mode:
2. Asynchronous-Commit Mode:
o The primary replica commits the transaction directly without waiting for
confirmation from the secondary replicas.
Q8: What is the failover process, and when will SQL Server decide to perform
failover in the SQL Server Always On Availability Group?
• Failover Process:
o The failover process involves the primary role and the secondary role
being interchangeable between the availability replicas.
• Failover Triggers:
The Availability Group Listener is a virtual network name that allows users to connect to
the primary or secondary replicas. It provides a single endpoint for applications to
connect to the Availability Group, regardless of which replica is currently the primary.
Q10: When defining a Windows Failover Cluster to build an SQL Server Always On
Availability Group over it, will we use the cluster option "Add all eligible storage to
the cluster"? Why?
No, you should uncheck the "Add all eligible storage to the cluster" option. This is
because the Always On Availability Group feature works based on having dedicated
storage for each replica without shared storage between the replicas.
1. Node Majority:
o Each cluster node gives one vote. Suitable for clusters with an odd
number of nodes.
o Each cluster node gives one vote, with an additional vote for the cluster
quorum disk. Suitable for clusters with an even number of nodes.
o Each cluster node gives one vote, with an additional vote for a shared file.
Suitable for clusters with an even number of nodes.
No, it is not considered a best practice. With each node having one vote, the cluster will
be down when one of the nodes goes down, losing the advantages of the high
availability concept. It is better to use a quorum configuration mode that provides more
resilience, such as Node and Disk Majority or Node and File Share Majority.
Q13: How can we enable the Always On Availability Group for a specific SQL Server
instance?
5. Move to the Always On Availability page under the SQL Server Service
properties window.
Q14: List some of the pre-requisites that the SQL Server Engine will check before
adding a database to the Availability Group?
Q15: What are the backup preference options supported in SQL Server Always On
Availability Group?
1. Preferred Secondary
2. Secondary Only
3. Primary
4. Any Replica
Q16: How many secondary replicas can we configure in SQL Server 2016?
Q17: What is the difference between configuring the secondary replica as readable
or read-intent only?
• Readable Secondary:
• Read-Intent Only:
Q18: What is the SQL Server Always On Availability Group Read-Only Routing List?
The Read-Only Routing List is a feature introduced in SQL Server 2014 that redirects
read-only workload to the first available secondary replica specified in a predefined
routing list. This feature ensures that read-only queries are efficiently handled by the
secondary replicas, provided the application connection string includes
the Application Intent=Readonly parameter.
Q19: What is the difference between the Direct Seeding and Full Backup and Log
Backup initial synchronization processes in Always On Availability Group?
• Direct Seeding:
Q20: How can we configure an SQL Server Always On Availability Group with a
multi-subnet network?
o Assign one IP address from each subnet to the Availability Group listener.
This ensures that the listener can be accessed from different subnets,
providing high availability and load balancing.
By following these steps and understanding the differences between various HA/DR
solutions, you can effectively implement and manage a robust SQL Server environment
in large companies.
SQL Server Database Recovery Models and Their Impact on Transaction Logs
SQL Server offers three main recovery models for databases: Full, Simple, and Bulk-
Logged. Each recovery model affects how the SQL Server Engine works with the
transaction logs, which in turn influences the way high availability and disaster recovery
(HA/DR) solutions are implemented.
• Description: This model logs all transactions, including bulk operations, to the
transaction log. It provides the highest level of data protection and allows for
point-in-time recovery.
• Transaction Log Impact: The transaction log grows continuously and must be
managed through regular log backups. Without log backups, the transaction log
can grow indefinitely, leading to performance issues and disk space constraints.
• HA/DR Solutions:
o Log Shipping: Requires the Full recovery model to capture and ship
transaction log backups.
• Description: This model logs only the transactions needed to maintain the
database's integrity. It does not support point-in-time recovery and automatically
truncates the transaction log after each checkpoint.
• HA/DR Solutions:
• Description: This model is a hybrid between the Full and Simple recovery
models. It logs bulk operations minimally, which can reduce the size of the
transaction log. It supports point-in-time recovery but may not be as robust as
the Full recovery model for large bulk operations.
• Transaction Log Impact: The transaction log grows less than in the Full recovery
model for bulk operations but still requires regular log backups to manage its
size.
• HA/DR Solutions:
In today's IT-driven world, the availability of critical systems is paramount for business
success and growth. During Service Level Agreement (SLA) discussions, terms
like Recovery Time Objective (RTO) and Recovery Point Objective (RPO) are often
discussed. RTO refers to the time it takes to restore a system to its operational state,
while RPO refers to the maximum acceptable amount of data loss measured in time.
High Availability (HA) ensures that SQL Server instances or databases are available
and reachable with minimal downtime in case of server crashes or failures. The
availability is often measured by the number of 9's in the availability percentage and the
total annual downtime:
Disaster Recovery (DR) ensures that the system can be brought online and serve users
in a secondary site in case of a catastrophic event at the primary datacenter, such as an
earthquake, flood, or war.
1. Log Shipping
• Components:
• Process:
o Log Backup: Transaction log backups are taken from the primary server
and restored on the secondary server.
o SQL Server Agent Jobs: Three jobs manage the backup, copy, and restore
processes.
2. Transactional Replication
• Process:
o Log Reader Agent: Monitors the transaction log and copies transactions
to the distribution database.
• Transaction Log Impact: Requires the Full recovery model to capture and
replicate transactions.
3. Database Mirroring
• Components:
• Synchronization Modes:
• Process:
• Components:
o Cluster Nodes: Multiple servers with the same hardware and software.
• Process:
o Failover: If the active node fails, the resource group ownership is moved
to another node, and the SQL Server instance is brought online on the
new node.
• Transaction Log Impact: No direct role for the transaction log, as the database
is hosted and online on one node at a time.
o Primary Replica: The main server where the databases are available for
read-write connections.
• Process:
The transaction log is a critical component in SQL Server's HA/DR solutions. It records
all transactions and their effects on the database, allowing for:
• Data Integrity: Ensuring that all changes are logged and can be rolled back if
necessary.
The backup database is further classified into two preliminary backup types
1. Backup Database
2. Backup Log
Let’s deep dive and review each of the database backup command topics to get a better
understanding of what it is all about. In this article, we will find an answer for FAQs
about the SQL Server database backup. We will learn more about database backup.
• Data is always the target and remain vulnerable for various threats
• Critical downtime
• It all depends on the amount of time it takes to redo the work. If it’s minor; then it
can be ignored. If this is a major data loss, it may take several business days and
it could feasibly end up in a heavy loss for the organization.
A Backup is a process to create a copy of data and it can be used to reconstruct the
data in case of any failures.
Backing up your SQL Server databases, running test restores procedures on your
backups, and storing copies of backups in a safe, on-site, off-site, and cloud location
protects and safeguard the data from potentially catastrophic or various types of data
loss.
The following are the different types of SQL Server database backups.
• Full
• Differential
• Transactional Log(T-Log)
• Copy-Only
• File
• FileGroup
• Partial
• Mirror
The type of a database backup depends on the database recovery model of the
database.
The Recovery Model is a property of a database that controls how the transactions are
logged.
The design of entire database and recovery procedures based on the context of the
recovery model of the database.
In the following example, query the sys.databases catalog view the recovery model of
the all the databases
The following example, the recovery model of the model database is set to FULL using
the SET RECOVERY option of the ALTER DATABASE statement.
In this backup type, the whole database is backed up. This is the base for any type of
backups. In order to have further differential or transaction log backups, you must
create the full database backup.
How can I find the progress of percentage completion of the database backup?
Use the keyword STATS in the T-SQL to monitor backup progress status. This can also be
used with restore command to measure the progress.
Use the keyword FORMAT and COMPRESSION to format and compress the database
backup.
On specifying the INIT keyword, all the backup sets are overwritten.
By default, the NOINIT option is enabled. It means that the backup will append to other
backups in the file
11. How can I get Files and Filegroup information in SQL Server?
You can query the sys,filegroups joined with sys. databases_files to get the filegroup
related information.
SELECT
dbf.name AS filename,
dbf.size/128 AS FileSizeMB,
12. What are system stored procedures that provide database information?
• sp_helpdb
• sp_helpfile
• sp_helpfilegroup
sp_helpdb ‘PowerSQL’
On specifying the database name, it displays the database information along with the
list all the files and related filegroup of the database
sp_helpfile
sp_helpfile PowerSQL_1
On specifying the parameter, the file, it will list the details of that specified file and
associated details.
sp_helpfilegroup
sp_helpfilegroup lists all the filegroups and number of associated data files in each
filegroup.
On specifying the filegroup, the output lists the specific filegroup and associated data
file details.
A Differential backup is also a type of SQL Server database backup where it copies all
the data that has changed since the last full backup.
14. What are T-Log backups and How can I create T-log (Transaction-log) backups?
The transaction log records every modification made to the databases. The records are
maintained in such a way that the system can be brought to a consistent state at any
point of time with minimal or no data loss.
For T-Log backup, the full backup is the base. It takes complete log file data to write to a
backup file.
The transaction log backup depends on the database recovery model and it’s relevant
for the databases that are using the full or bulk-logged recovery models.
To execute the BACKUP LOG statement to back up the transaction log, specify the
database name and backup device
How can I continue the database backup processes despite they encounter an error?
It’s basically overriding the default behavior of database backup process using
CONTINUE_AFTER_ERROR. On error, the backup process will stop the process.
In case of failure, it is required to start the recovery process, the first and foremost
important step is intended to ensure take care of tail part of the transaction before
starting the restoration process is called tail-log backup.
WITH CONTINUE_AFTER_ERROR keyword, the SQL Server will override the default
behavior even though it’s generating an error to complete the backup process.
USE MASTER
GO
It’s a special type of backup. It is independent of the conventional backups and it will
not have an impact on the overall backup process.
In simple words, it is used to create a full database or transaction log backup without
breaking the log chain
In some cases, it is required to create multiple copies of data into different files. You can
create a maximum of three mirror copies of the data at a time.
Partial database backup is one of the rarely used backup methods. All though it works
with all recovery models, it is basically designed for simple database recovery model
database. This provides flexibility for backing up only READ_WRITE_FILEGROUPS.
This type of backup is mainly used where there is an issue with storage space.
In this type of database backup, the data will be split into parts and can be very useful
during space constraints. Striped backup is a process of taking backup to different
locations.
Every SQL Server database must have a minimum of a data file and a log file. We can
also create more than one files and it can be grouped together in filegroups for easier
file management and administration purpose.
File Backup
If you want the backup to expire, use WITH EXPIREDATE clause option in the backup
database T-SQL. The following example shows How can I back up with an expiration
date on Jun 28, 2018:
If you want to retain the backup for the only specific number of days then use the WITH
RETAINDAYS clause with the database backup command.
• Create certificate B
USE MASTER
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'PowerSQL$2018'
CREATE CERTIFICATE BackupServerCert WITH SUBJECT = 'Backup certificate'
BACKUP DATABASE PowerSQL TO DISK = N'F:\PowerSQL\PowerSQL.BAK'
WITH FORMAT,
ENCRYPTION
(
ALGORITHM = AES_256,
SERVER CERTIFICATE = BackupServerCert
Every time
Log Truncation During Checkpoint
Process (LTP) backup background run
Life process During backup process against the database
Point-in-time
recovery Yes No No
Log backup
support Yes Yes No
Piecemeal
Restore Yes Yes Yes
Log Shipping
Support Yes Yes No
Database
Mirroring
Support Yes No No
Database
Replication
Support Yes Yes Yes
System databases are an essential component of SQL Server engine for the functioning
of a server instance. The system databases are critical as it stores meta-data of the
user-defined databases. It must be backed up after every significant update as we do it
for user-defined databases. The system databases that you must always back up
include msdb, master, model and configuration databases.
System Recovery
database Description Backup? model
User
model It’s a template for all databases. Yes configurable*
Configure
Distribution Configuration database for replication Yes Simple