0% found this document useful (0 votes)
67 views49 pages

SQL Interviw Quetions 2025

The document outlines a 30-day MS SQL Database Administrator course by Mukesh Chaurasia, including a comprehensive list of interview questions and sample answers for both technical and non-technical aspects. It covers topics such as database environment overview, backup strategies, incident handling, and performance tuning, along with migration and upgrade considerations. Additionally, it provides insights into tools and methods for assessing SQL Server environments and best practices for ensuring data integrity and system reliability.

Uploaded by

venkatesh.g773
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views49 pages

SQL Interviw Quetions 2025

The document outlines a 30-day MS SQL Database Administrator course by Mukesh Chaurasia, including a comprehensive list of interview questions and sample answers for both technical and non-technical aspects. It covers topics such as database environment overview, backup strategies, incident handling, and performance tuning, along with migration and upgrade considerations. Additionally, it provides insights into tools and methods for assessing SQL Server environments and best practices for ensuring data integrity and system reliability.

Uploaded by

venkatesh.g773
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


MS SQL INTERVIEW QUESTION LIST

Absolutely, preparing for both technical and non-technical questions is


crucial for a successful SQL Server job interview. Here are some sample
answers to the non-technical questions you mentioned:

1. Tell me something about yourself and your experience in SQL Server?

"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."

2. Give me an overview of your database environment like the number


of instances, databases, biggest database size, etc.?

"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."

3. Explain your backup and database maintenance strategy for your


biggest critical OLTP database?

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


"For our largest critical OLTP database, we have a comprehensive backup and
maintenance strategy to ensure data integrity and availability. We perform full backups
daily, differential backups every four hours, and transaction log backups every 15
minutes. These backups are stored in multiple locations, including on-site and off-site,
to mitigate the risk of data loss. Additionally, we use SQL Server Maintenance Plans and
custom scripts to automate index maintenance, statistics updates, and integrity
checks. We also have a disaster recovery plan in place, with regular testing to ensure
that we can quickly restore the database in case of any issues."

4. How do you handle major incidents?

"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."

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


6. Suppose there is a database issue, and you don’t have any solution.
You did everything to find the solution to fix the issue, but you did not
get anything. What would be your next step to handle this situation?

"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:

1. Automated Backup and Maintenance Solution:


I developed an automated backup and maintenance solution using SQL Server
Agent jobs and PowerShell scripts. This solution not only reduced the manual
effort required for backups and maintenance but also improved the reliability of
our backups. The system now automatically verifies the integrity of backups and
sends alerts if any issues are detected. This project was recognized by our
leadership for significantly enhancing our disaster recovery capabilities and
reducing the risk of data loss.

2. Performance Tuning for a High-Volume OLTP System:


We had a high-volume OLTP system that was experiencing frequent performance
bottlenecks. I led a performance tuning initiative that involved analyzing query
execution plans, optimizing indexes, and fine-tuning server configurations. The
result was a 30% improvement in query response times, which greatly enhanced

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


user satisfaction. Our client was very pleased with the outcome, and I received a
commendation for my work on this project."

MIND – MAP of Interview Q&A

❖ MS SQL SERVER Interview Question


➢ Non-Technical Question
▪ Tell me about yourself and experience
▪ Overview of database environment
▪ Backup and maintenance strategy
▪ How do you handle major incidents?
▪ Last issue faced and fixed
▪ Handling unresolved database issue
▪ Deliveries / solutions recognized by clients/leaders
➢ Technical Question
▪ Page and Extent Relation
• Page size 8KB
• Extent collection of 8 pages
• Extent size 64KB
▪ Pages allocated to log file (zero)
▪ Differential Backup Tracking
• Internal data structure tracks modified extents
• Differential Changed Map (DCM) pages
• Bit value 1 for modified, 0 for not modified
▪ Change Logical File Name
• ALTER DATABASE statement
• GUI (database properties)
▪ Impact of multiple log files (no performance gain)
• Skips zeroing process for data files
• Speeds up space allocation

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


• Does NOT work for log files
▪ Instant File Initialization (IFI)
• Skips zeroing process for data files
• Speed up space allocation
• Does not work for log files
▪ Secure SQL Server Instance
• Harden OS
• Apply security patches
• Fix vulnerability
• Install only required features
• Change default port
• Disable sa account
• Use windows authentication
• Disable SQL browser service
• Use encryption
• Regular audit for logins
• Assign appropriate permission
• Remove logins for left employees
• Use strong password
▪ Data Protection & Business Continuity Options
• Backup and Restore
• AOAG
• Always on failover cluster instance (AOFCI)
• Log shipping
• Replication
▪ Transparent Data Encryption (TDE) Negative Side
• Encrypt tempdb
• Performance overhead
• Data in transit/buffer cache not encrypted
• Backup/secure certificate/key needed

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


▪ Performance Issues Post Upgrade
• Change compatibility level
• Review query plan, use legacy cardinality estimator
• Enable Query store
• Parameter sniffing (recompile query)
• Find missing indexes
• Run update stats
▪ Always On in SQL Server
• Term for business continuity features
• Covers availability group and feature cluster instance
▪ AG between Windows and Linux
• Yes, possible
• Use Pacemaker
• Cluster type EXTERNAL
▪ Distributed Availability Group
• Added in SQL Server 2016
• Spans multiple availability group
• Created on top of 2+ existing group
• Each AG has its own WSFC
▪ Patch Always On AG with Minimum Downtime (Rolling Upgrade)
• Patch DR replica
• Change failover mode to manual
• Patch Secondary Replica (primary data center)
• Reboot Secondary
• Failover to newly patched secondary
• Patch previous primary (now secondary)
• Reboot
• Failback to original primary
▪ AG between SQL Server FCI
• Yes, possible

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


• Automatic failover not possible
▪ Restore Availability Database
• Can not restore directly
• Evict from AOAG
• Restore database
• Add back to AOAG
▪ Latency Issues in Secondary Replica Reports
• Long-running transactions
• Resource contentions in secondary
• Poor network throughout
▪ Long Running Transactions Always On AG
• Read operations use snapshot isolation
• Snapshot isolation doesn’t see updates from open transactions
• Read beginning point of active transactions
▪ Impact of Log Shipping Failover on Replication
• Replication stop working
• Agents
• Don’t connect to secondary DB
• Resumes on failback
▪ Tool for troubleshoot AOAG
• SQL Server Error Logs
• Cluster log files
• AG extended events
• AG wait types
• AG health detection logs
• DMVs and system catalog views
▪ Resource semaphore wait Type
• Internal algorithm for memory grants
• Query waits if request memory not granted
• First come first server

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


▪ Get Requested and granted memory details
• Sys.dm_exec_query_memory_grants DMV

SQL Server Upgrade and Migrate Related Interview Question and Answer

General Interview Questions

1. What is the difference between SQL Server Upgrade and Migration?

• 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.

• Migration: This involves moving SQL Server to a different server or platform,


which may include changes in hardware, operating system, or cloud provider.
Migration can also involve an upgrade, but it's not always necessary.

Planning & Prerequisites

2. How do you plan for a SQL Server upgrade or migration?

• Assessment: Use the Data Migration Assistant (DMA) to identify deprecated


features and compatibility issues.

• Inventory: List all databases, linked servers, jobs, logins, SSIS packages, and
application connections.

• Capacity Planning: Analyze CPU, memory, and disk I/O requirements.

• Compatibility Check: Identify any T-SQL syntax or features that are deprecated
in the target version.

• Choose Upgrade Method: Decide between in-place or side-by-side upgrade.

• Testing: Perform a dry-run upgrade in a lower environment to ensure everything


works as expected.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


• Backup & Rollback: Ensure that backups and rollback plans are tested and
documented.

• Downtime Window: Plan for an acceptable downtime window with


stakeholders.

3. What tools do you use to assess SQL Server before migration or upgrade?

• Data Migration Assistant (DMA): For compatibility and feature parity checks.

• Database Experimentation Assistant (DEA): For A/B performance testing.

• SQL Server Upgrade Advisor: For older versions (now deprecated).

• sp_Blitz: A community tool to assess health and best practices.

4. What are the supported SQL Server upgrade paths?

Microsoft supports direct upgrades from two versions prior:

• SQL Server 2014 → 2019

• SQL Server 2016 → 2022

For other scenarios, use intermediate upgrades or backup-restore methods.

Upgrade Methods

5. What is the difference between in-place and side-by-side upgrade?

• In-Place Upgrade:

o Overwrites the existing SQL instance.

o Faster, but higher risk.

o Downtime is required.

o Risk of failure affecting the production environment.

• Side-by-Side Upgrade:

o Installs SQL on a new machine or instance.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


o Safer, with better rollback options.

o Allows for gradual migration.

o Easier to revert to the old server if needed.

6. What method do you recommend for production environments? Why?

• Side-by-Side Upgrade: This is generally preferred for production environments


due to:

o Lower risk.

o Better rollback options.

o Easier testing and validation.

7. How do you move logins, jobs, and linked servers?

• Logins: Use sp_help_revlogin or PowerShell to script logins with SIDs and


passwords.

• 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

8. How do you migrate a database from on-prem to Azure SQL Database?

• Assessment: Use DMA to assess compatibility.

• Migration Methods:

o Use Azure Database Migration Service (DMS) for a seamless migration.

o Use bacpac export/import for smaller databases.

o For large databases, use transactional replication or log shipping to


minimize downtime.

9. What are common challenges during upgrade/migration?

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


• Application Compatibility Issues: Some applications may not work with the
new version.

• Deprecated Feature Usage: Features that are no longer supported in the new
version.

• Collation Mismatches: Differences in collation settings can cause issues.

• Logins and Orphaned Users: Ensuring that logins and users are correctly
mapped.

• Performance Regressions: Some queries may perform worse in the new


version.

• SQL Agent Jobs Failing: Jobs may fail due to version-specific syntax changes.

Post-Migration/Upgrade Tasks

10. What are the post-upgrade/migration steps?

• Validate Data Integrity: Run DBCC CHECKDB to ensure data integrity.

• Rebuild/Reorganize Indexes: Optimize indexes for better performance.

• Update Statistics: Ensure that statistics are up-to-date.

• Run Integrity Checks: Verify that jobs, linked servers, and other components are
functioning correctly.

• Set Compatibility Level: Update the compatibility level to leverage new


features.

• Monitor Performance: Continuously monitor performance metrics.

• Update Documentation and Monitoring Tools: Ensure that all documentation


and monitoring tools are updated to reflect the new environment.

Performance Considerations

11. Why should you not immediately change compatibility level after migration?

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


• Some applications may not be compatible with the latest compatibility level. It's
best to keep the old level for initial testing and gradually update after validation
to avoid any issues.

12. How do you compare performance before and after migration?

• Use Database Experimentation Assistant (DEA): For A/B performance testing.

• 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.

Disaster Recovery & Rollback

13. What is your rollback strategy during a migration?

• Keep the Source Server Online: Maintain the source server in read-only mode
until validation is complete.

• Use DNS Aliasing: This allows for an easy switch-back if needed.

• Have Backups and Scripts Ready: Prepare for reverse migration by having
backups and scripts ready to restore the old environment.

Cloud-Based Interview Questions

14. What’s the difference between migrating to Azure SQL Database vs Azure
SQL Managed Instance?

• Azure SQL Database:

o PaaS, Single DB: Managed service for individual databases.

o No SQL Agent: Does not support SQL Server Agent.

o No Cross-Database Joins: Limited to a single database.

o Requires Code Changes: May need to modify application code to work


with the PaaS model.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


• Azure SQL Managed Instance:

o PaaS, Instance-Level: Managed service that supports an entire SQL


Server instance.

o Has SQL Agent: Supports SQL Server Agent.

o Supports Cross-Database Joins: Can join data across multiple


databases.

o Minimal Changes Needed: Generally requires fewer application code


changes.

Bonus

15. What changes in SQL Server 2022 should be considered before upgrading?

• Contained Availability Groups: New feature for managing availability groups.

• Ledger for Blockchain: Enhanced security features for blockchain.

• Intelligent Query Processing (IQP) Enhancements: Improvements in query


optimization.

• Azure Synapse Link: Integration with Azure Synapse for real-time analytics.

• Security Enhancements: Such as improvements in Azure Active Directory (AAD)


authentication.

• Validate Deprecated/Removed Features: Ensure that any deprecated or


removed features are not in use in your current environment.

SQL Server Patching Related Interview Question and Answer

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:

1. Plan and Preparation

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


Backup:

• 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:

• Test in a Non-Production Environment: Always test the patches in a non-


production environment first. This helps ensure compatibility and identifies any
potential issues that could disrupt the production environment.

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:

• Download the Appropriate Patches: Obtain the necessary patches from


Microsoft's official website or the relevant source. Ensure you download the
correct version for your SQL Server.

SQL Server Agent:

• 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.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


Restarting Services:

• 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.

3. Verification and Monitoring

Database Consistency Check:

• 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:

• Monitor Server Performance: Closely monitor the server's performance


metrics, such as CPU usage, memory usage, disk I/O, and query performance.
Use tools like SQL Server Profiler, Performance Monitor, or Query Store to track
any changes.

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.

Hotfixes vs. Patches:

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


• Understand the Differences: Be aware of the difference between hotfixes
(small, specific fixes) and cumulative updates (larger, more comprehensive
updates). Choose the appropriate type of update based on your needs.

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.

SQL Server Joins Interview Question and Answer

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:

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


1. Inner Join:

o Definition: Returns only the rows that have matching values in both
tables.

o Syntax:

SELECT * FROM table1

INNER JOIN table2

ON table1.common_column = table2.common_column;

o Example:

SELECT Orders.OrderID, Customers.CustomerName

FROM Orders

INNER JOIN Customers

ON Orders.CustomerID = Customers.CustomerID;

o Use Case: When you need to retrieve data that exists in both tables.

2. Left Join (or Left Outer Join):

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:

SELECT * FROM table1

LEFT JOIN table2

ON table1.common_column = table2.common_column;

o Example:

SELECT Orders.OrderID, Customers.CustomerName

FROM Orders

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


LEFT JOIN Customers

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.

3. Right Join (or Right Outer Join):

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:

SELECT * FROM table1

RIGHT JOIN table2

ON table1.common_column = table2.common_column;

o Example:

SELECT Orders.OrderID, Customers.CustomerName

FROM Orders

RIGHT JOIN Customers

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.

4. Full Join (or Full Outer Join):

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:

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


SELECT * FROM table1

FULL JOIN table2

ON table1.common_column = table2.common_column;

o Example:

SELECT Orders.OrderID, Customers.CustomerName

FROM Orders

FULL JOIN Customers

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.

Additional Types of Joins

5. Cross Join:

o Definition: Returns the Cartesian product of the two tables, meaning


every row from the first table is combined with every row from the second
table.

o Syntax:

SELECT * FROM table1

CROSS JOIN table2;

o Example:

SELECT Orders.OrderID, Customers.CustomerName

FROM Orders

CROSS JOIN Customers;

o Use Case: When you need to generate all possible combinations of rows
from the two tables.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


6. Self Join:

o Definition: A table is joined with itself, often used to compare rows within
the same table.

o Syntax:

SELECT a.column, b.column

FROM table a

JOIN table b

ON a.common_column = b.common_column;

o Example:

SELECT a.EmployeeID, a.EmployeeName, b.ManagerName

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.

• Cross Join: Returns the Cartesian product of the two tables.

• Self Join: Joins a table with itself to compare rows within the same table.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


Understanding these different types of joins is crucial for effectively querying and
combining data from multiple tables in SQL.

SQL Server Mirroring and Log Shipping Interview Question and Answer

1. What is Mirroring?

Mirroring is a high-availability solution designed to keep a hot standby server


transactionally consistent with the primary server. In a mirrored setup, transaction log
records are sent directly from the primary server to the secondary server, ensuring that
the secondary server remains in sync with the primary server. This provides a near-real-
time backup that can be used to quickly fail over in case the primary server goes down.

2. What is Log Shipping?

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:

o Real-Time Synchronization: Transaction log records are sent in near real-


time, keeping the secondary server up-to-date.

o Hot Standby: The secondary server is a hot standby, meaning it can be


quickly brought online if the primary server fails.

o Automatic Failover: Can be configured for automatic failover, reducing


downtime.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


o Complexity: Generally more complex to set up and manage.

• Log Shipping:

o Periodic Synchronization: Transaction logs are backed up and restored


at regular intervals, which means the secondary server may be slightly
behind the primary.

o Warm Standby: The secondary server is a warm standby, meaning it can


be brought online manually if the primary server fails.

o Manual Failover: Requires manual intervention to fail over, which can


increase downtime.

o Simplicity: Easier to set up and manage compared to mirroring.

Both solutions are useful for different scenarios, depending on the required level of
availability and the resources available for management.

SQL Server Always On Availability Groups Interview Questions &


Answers

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:

• Minimizing Downtime: Ensuring that business operations can continue even in


the event of hardware failures, software issues, or other disruptions.

• Data Protection: Safeguarding data against loss or corruption.

• Compliance: Meeting regulatory and industry standards for data availability and
recovery.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


• Customer Satisfaction: Maintaining service levels and customer trust by
ensuring that applications and services remain accessible.

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

4. Always On Failover Cluster

5. SQL Server Always On Availability Groups

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 Failover Cluster: Resources such as storage, network name,


and virtual IPs are shared and can be owned by only one cluster node at a
given time.

o Always On Availability Groups: Each node has its own resources, with
no resource sharing concept.

• Read Operations:

o Always On Failover Cluster: No option to read from the secondary


server, as there are no database copies hosted in these secondary nodes.

o Always On Availability Groups: Supports up to eight secondary replicas,


from which you can perform read operations or route read-only workload.

• High Availability vs. Disaster Recovery:

o Always On Failover Cluster: Can be used as a High Availability solution


only.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


o Always On Availability Groups: Can be used as both a High Availability
and Disaster Recovery solution.

• Configuration Level:

o Always On Failover Cluster: Configured at the instance level, and


failover is performed at the instance level.

o Always On Availability Groups: Configured at the database level, and


failover is performed at the databases group level.

Q4: What are the differences between the SQL Server Database Mirroring and the
SQL Server Always On Availability Groups?

• Read Operations:

o Database Mirroring: You cannot read from the secondary database.

o Always On Availability Groups: You can read from the secondary


databases.

• Number of Replicas:

o Database Mirroring: Configured between two servers only.

o Always On Availability Groups: Supports up to eight secondary replicas.

• Automatic Failover:

o Database Mirroring: Automatic failover is possible only if a witness


server is configured.

o Always On Availability Groups: Automatic failover is always possible


between the primary and secondary replicas.

• Configuration Level:

o Database Mirroring: Configured for each database separately, and


failover is performed at the database level.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


o Always On Availability Groups: Configured to involve multiple databases
at the same time using a single wizard, and failover is performed at the
databases group 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:

o Synchronous-Commit Mode: The primary replica waits for confirmation


from the secondary replicas that the logs are written to the transaction log
file before committing the transaction.

o Asynchronous-Commit Mode: The primary replica commits the


transaction directly without waiting for confirmation from the secondary
replicas.

Q6: What is the Availability Group?

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:

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


o The primary replica waits for confirmation from the secondary replicas
that the logs are written to the transaction log file before committing the
transaction.

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:

o Server-Level Failure: The failover process will be initiated in case of any


server-level failure.

o Database-Level Issues: No failover process will be performed in case of


database issues such as data loss or corruption unless the Database
Level Health Detection feature is enabled.

Q9: What is the Availability Group Listener?

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.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


Q11: What are the quorum configuration modes available in Windows Failover
Clustering?

1. Node Majority:

o Each cluster node gives one vote. Suitable for clusters with an odd
number of nodes.

2. Node and Disk Majority:

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.

3. Node and File Share Majority:

o Each cluster node gives one vote, with an additional vote for a shared file.
Suitable for clusters with an even number of nodes.

4. No Majority (Disk Only):

o The status of the cluster depends completely on the availability of the


quorum disk.

Q12: Is it considered a best practice to create a SQL Server Always On Availability


Group with two replicas and configure the quorum using Node Majority mode?
Why?

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?

1. Open SQL Server Configuration Manager.

2. Expand SQL Server Services.

3. Browse for the SQL Server Database Engine service.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


4. Right-click on the service and select Properties.

5. Move to the Always On Availability page under the SQL Server Service
properties window.

6. Check the "Enable Always On Availability Groups" option.

7. Restart the service to apply the changes.

Q14: List some of the pre-requisites that the SQL Server Engine will check before
adding a database to the Availability Group?

1. The database must be configured with a Full recovery model.

2. A full backup must be taken from the database.

3. The database must not be participating in another 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?

SQL Server 2016 supports up to eight secondary replicas.

Q17: What is the difference between configuring the secondary replica as readable
or read-intent only?

• Readable Secondary:

o Allows read-only access to the secondary databases.

• Read-Intent Only:

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


o The secondary replica serves read-only workload only, and the
application connection string must explicitly mention the Application
Intent=Readonly parameter.

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?

• Full Backup and Log Backup:

o The initial synchronization is performed by taking full and transaction log


backups of the primary database and restoring them to the secondary
replicas.

• Direct Seeding:

o Introduced in SQL Server 2016, this method initializes the secondary


databases automatically using Microsoft SQL Server Virtual Device
Interface (VDI) backup over the network, eliminating the need for a
network share.

Q20: How can we configure an SQL Server Always On Availability Group with a
multi-subnet network?

To configure an SQL Server Always On Availability Group with a multi-subnet network,


you need to:

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


• Configure the Availability Group Listener:

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 Transaction Log and High Availability Solutions

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.

1. Full Recovery Model

• 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.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


o Database Mirroring: Requires the Full recovery model to ensure
transactional consistency.

o Always On Availability Groups: Requires the Full recovery model to


synchronize transaction logs between replicas.

2. Simple Recovery Model

• 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.

• Transaction Log Impact: The transaction log is truncated regularly, which


means it does not grow as much as in the Full recovery model. However, this
also means that you cannot recover to a specific point in time.

• HA/DR Solutions:

o Log Shipping: Not supported because it requires transaction log


backups.

o Database Mirroring: Not supported because it requires the Full recovery


model.

o Always On Availability Groups: Not supported because it requires the


Full recovery model.

3. Bulk-Logged Recovery Model

• 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:

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


o Log Shipping: Supported, but the minimal logging of bulk operations can
complicate recovery.

o Database Mirroring: Supported, but the minimal logging of bulk


operations can complicate recovery.

o Always On Availability Groups: Supported, but the minimal logging of


bulk operations can complicate recovery.

High Availability and Disaster Recovery Overview

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.

For database administrators in large companies, providing a reliable HA/DR solution is


crucial to minimize downtime and ensure data integrity. Microsoft SQL Server offers
several technologies to achieve this:

High Availability Concepts

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:

Number of 9's Availability Percentage Total Annual Downtime

2 99% 3 days, 15 hours

3 99.9% 8 hours, 45 minutes

4 99.99% 52 minutes, 34 seconds

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia

Number of 9's Availability Percentage Total Annual Downtime

5 99.999% 5 minutes, 15 seconds

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.

High Availability and Disaster Recovery Technologies in SQL Server

1. Log Shipping

• Description: A database-level HA solution suitable for less mission-critical


databases with flexible RPO and RTO.

• Components:

o Primary Server: The main server where the database is hosted.

o Secondary Server(s): Standby servers used for reporting.

• Process:

o Full Backup: The primary database is backed up and restored on the


secondary server.

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.

• Transaction Log Impact: Requires the Full recovery model to capture


transaction log backups.

2. Transactional Replication

• Description: A real-time, database-level HA solution that distributes database


tables to one or more secondary servers.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


• Components:

o Publisher: The primary server.

o Subscribers: Secondary servers.

• Process:

o Snapshot Agent: Prepares the initial snapshot of the database objects.

o Log Reader Agent: Monitors the transaction log and copies transactions
to the distribution database.

o Distribution Agent: Copies the snapshot and transaction log backups to


the subscribers.

• Transaction Log Impact: Requires the Full recovery model to capture and
replicate transactions.

3. Database Mirroring

• Description: A database-level HA solution that can be configured on databases


with the Full recovery model.

• Components:

o Principal Server: The primary server.

o Mirror Server: The secondary server.

o Witness Server (Optional): Monitors the connection and performs


automatic failover.

• Synchronization Modes:

o High-Safety (Synchronous): The transaction is committed on the


principal server after it is committed and written to the transaction log on
the mirror server.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


o High-Performance (Asynchronous): The transaction is committed on the
principal server without waiting for the mirror server, reducing latency but
increasing the risk of data loss.

• Process:

o Initial Synchronization: A full backup and transaction log backup are


restored on the mirror server.

o Ongoing Synchronization: Active transaction log records are sent to the


mirror server and redone.

• Transaction Log Impact: Requires the Full recovery model to ensure


transactional consistency.

4. Always On Failover Cluster

• Description: An instance-level HA solution built on Windows Server Failover


Clustering (WSFC).

• Components:

o Cluster Nodes: Multiple servers with the same hardware and software.

• Process:

o Resource Ownership: SQL Server services and resource groups (shared


storage, network name, virtual IPs) are owned by one node at a time.

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.

5. Always On Availability Groups

• Description: A database-level HA solution introduced in SQL Server 2012, built


on WSFC.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


• Components:

o Primary Replica: The main server where the databases are available for
read-write connections.

o Secondary Replicas: Up to eight secondary servers that can be used for


read-only connections.

• Process:

o Initial Synchronization: A full backup and transaction log backup are


restored on the secondary replicas.

o Ongoing Synchronization: Transaction log records are sent from the


primary replica to the secondary replicas, where they are written to the
transaction log file and redone.

• Transaction Log Impact: Requires the Full recovery model to synchronize


transaction logs between replicas. Server-level changes not written to the
transaction log (e.g., logins, linked servers, SQL Agent jobs) must be
synchronized manually.

Importance of the SQL Server Transaction Log

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.

• Point-in-Time Recovery: Restoring the database to a specific point in time.

• Synchronization: Facilitating the transfer of changes between the primary and


secondary replicas in solutions like Log Shipping, Database Mirroring, and
Always On Availability Groups.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia

SQL interview questions on database backups, restores and recovery

The backup database is further classified into two preliminary backup types

1. Backup Database

2. Backup Log

Each of the above types defines the type of data.

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.

1. Why are database backups so important?

They is so important because of following reasons:

• Data is always the target and remain vulnerable for various threats

• Un-reliable on hardware and software programs

• Importance of the data

• 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.

2. What is a SQL Server database backup?

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.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


3. What are different types of database backups?

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.

4. What is a database recovery model?

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.

5. How can I check the recovery model of the database?

In the following example, query the sys.databases catalog view the recovery model of
the all the databases

SELECT name, recovery_model_desc FROM sys.databases;

6. How can I change the recovery model?

The following example, the recovery model of the model database is set to FULL using
the SET RECOVERY option of the ALTER DATABASE statement.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


ALTER DATABASE model SET RECOVERY FULL

What permission is required to take a database backup?

By default to members of the sysadmin fixed server role and


the db_owner and db_backupoperator fixed database roles.

7. What is a full database backup?

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.

BACKUP DATABASE PowerSQL TO DISK='f:\PowerSQL\PowerSQL_FULL.BAK'

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.

BACKUP DATABASE PowerSQL TO DISK='f:\PowerSQL\PowerSQL_FULL.BAK' WITH STATS

8. How can I create a compressed backup on a newly formatted backup file?

Use the keyword FORMAT and COMPRESSION to format and compress the database
backup.

BACKUP DATABASE PowerSQL TO DISK='f:\PowerSQL\PowerSQL_FULL.BAK'

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


WITH STATS,FORMAT, COMPRESSION;

9. How can I overwrite to an existing backup file?

On specifying the INIT keyword, all the backup sets are overwritten.

BACKUP DATABASE PowerSQL TO DISK='f:\PowerSQL\PowerSQL_FULL.BAK' WITH


STATS,INIT

10. How can I append backup sets in SQL Server database?

By default, the NOINIT option is enabled. It means that the backup will append to other
backups in the file

BACKUP DATABASE PowerSQL TO DISK='f:\PowerSQL\PowerSQL_FULL.BAK'


WITH STATS, NOINIT
OR

BACKUP DATABASE PowerSQL TO DISK='f:\PowerSQL\PowerSQL_FULL.BAK'

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,

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


dfg.name AS FGName,
dfg.type_desc,
dbf.physical_name AS Physicalpath
FROM
sys.database_files AS dbf
INNER JOIN sys.filegroups AS dfg
ON
dbf.data_space_id = dfg.data_space_id

12. What are system stored procedures that provide database information?

The following the system stored procedures:

• 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

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


sp_helpfile is a subset of sp_helpdb and it returns files, filegroup, and their properties.

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.

13. What is a Differential backup?

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.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


BACKUP DATABASE PowerSQL TO DISK = N'f:\PowerSQL\PowerSQL_Diff.BAK' WITH
DIFFERENTIAL

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

BACKUP LOG PowerSQL TO DISK=N'f:\PowerSQL\PowerSQL_tlog.trc'

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.

BACKUP DATABASE PowerSQL TO DISK = N'f:\PowerSQL\PowerSQL_Diff.BAK' WITH


CHECKSUM, CONTINUE_AFTER_ERROR,STATS, FORMAT, COMPRESSION

15. What is a Tail-log backup?

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

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


BACKUP LOG PowerSQL TO DISK=N'f:\PowerSQL\PowerSQL_tlog.trc' WITH CHECKSUM,
CONTINUE_AFTER_ERROR,STATS
16. What is a Copy-only backup?

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

BACKUP DATABASE PowerSQL TO DISK = N'f:\PowerSQL\PowerSQL_Diff.BAK'


WITH COPY_ONLY,STATS, FORMAT, COMPRESSION

17. What is a mirror backup?

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.

BACKUP DATABASE PowerSQL


TO DISK = 'F:\PowerSQL\PowerSQL.BAK'
MIRROR TO DISK = 'F:\PowerSQL\PowerSQL_1.BAK'
MIRROR TO DISK = 'F:\PowerSQL\PowerSQL_2.BAK'
WITH FORMAT, COMPRESSION, STATs
GO

18. What is a Partial database backup?

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.

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


BACKUP DATABASE PowerSQL READ_WRITE_FILEGROUPS TO DISK =
N'f:\PowerSQL\PowerSQL_Diff.BAK' WITH COPY_ONLY,STATS, FORMAT, COMPRESSION

19. What is a Striped (Split) database backup in SQL Server?

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.

BACKUP DATABASE PowerSQL


TO DISK = 'F:\PowerSQL\PowerSQL.BAK',
DISK = 'F:\PowerSQL\PowerSQL_1.BAK',
DISK = 'F:\PowerSQL\PowerSQL_2.BAK'
WITH FORMAT, COMPRESSION, STATS=10

20. What is a file and filegroup backup?

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.

Using this method, the desired file\file group backup is possible

File Backup

Syntax: BACKUP DATABASE [DBNAME] FILE = N’FILENAME’ TO DISK = N’Path’

BACKUP DATABASE PowerSQL FILE = N'PowerSQL_Index' TO DISK =


N'F:\PowerSQL\PowerSQL_Index.BAK'

File Group Backup:

Syntax: BACKUP DATABASE [DBNAME] Filegroup = N’Filegroup Name’ TO DISK =


N’Path’

BACKUP DATABASE PowerSQL


Filegroup = N'PRIMARY',

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


Filegroup = N'SalesInMemFG' TO DISK = N'F:\PowerSQL\PowerSQL_PRIMARYFG.BAK'
WITH FORMAT, STATS
21. How can I set expiration dates for backups?

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:

BACKUP DATABASE PowerSQL TO DISK = N'F:\PowerSQL\PowerSQL_PRIMARYFG.BAK'


WITH EXPIREDATE = N'08/28/2018 00:00:00'

22. How can I retain backup for a specific number of days?

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.

BACKUP DATABASE PowerSQL TO DISK = N'F:\PowerSQL\PowerSQL.BAK' WITH


RETAINDAYS = 3 , FORMAT, STATS=10

23. How can I encrypt a database backup using certificate?

• Create master Key

• Create certificate B

• Backup the database

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

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia


),
STATS = 10
GO
24. What is the difference between FULL, Bulk-Logged and Simple recovery
models?

FULL BULK LOGGED SIMPLE

All, but minimal log for few operations such as


bulk operations(bcp, BULK INSERT) Select
into, Create index, alter index, drop index,
Log level All updatetext, and writetext Minimal

Every time
Log Truncation During Checkpoint
Process (LTP) backup background run
Life process During backup process against the database

Can it use for


Production
Server? Yes Depends – Yes/No Depends – Yes/No

Point-in-time
recovery Yes No No

Log backup
support Yes Yes No

Piecemeal
Restore Yes Yes Yes

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia

Log Shipping
Support Yes Yes No

Database
Mirroring
Support Yes No No

Database
Replication
Support Yes Yes Yes

25. What are system databases?

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

The database is used to record all of the system level


master information Yes Simple

User
model It’s a template for all databases. Yes configurable*

It is used by SQL Server Agent for job management and


it also stores a history of every backup and restore Simple
msdb operations Yes (default)

SECURITY LABEL: OFFICIAL


MS SQL DATABASE ADMINISTRATOR 30 DAYS COURSE

BY: Mukesh Chaurasia

A read-only database that contains copies of all


Resource system objects that ship with SQL Server No —

tempdb A workspace for SQL Server No Simple

Configure
Distribution Configuration database for replication Yes Simple

SECURITY LABEL: OFFICIAL

You might also like