Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

SQL Server Restore Interview Questions

$
0
0
By:Rajendra Gupta | Last Updated: 2018-12-24 || Related Tips:More > Professional Development Interview Questions DBA Problem

In my previous tip, we learned about interview question related to SQL Server database backups. In this part of the interview series, we will learn about SQL Server database restore interview questions

Solution

In this tip, let's start with questions related to the database restores in SQL Server. Before going to the interview go through the below links as a starting point.

SQL Server Backup Tips SQL Server Backup Tutorial SQL Server Restore Tips SQL Server Restore Tutorial SQL Server Recovery Models Q1. What are the enhancements in SQL Server2017 for differential backups?

Answer: In SQL Server 2017, the dynamic management view sys.dm_db_file_space_usage contains a new column called modified_extent_page_count. This column gives information about how many extents are modified after the full backup. We can use this field to calculate percentage change occurred in the database by using the below query.

SELECT
file_id,total_page_count,
modified_extent_page_count,
(100 * modified_extent_page_count)/total_page_count [percent_changed]
FROM sys.dm_db_file_space_usage Additional resources: SQL Server 2017 differential backup changes Q2. In SQL Server, normally we take transaction log backups for critical databases at a regular interval. Sometimes there might not be any change to the database but we issue a transaction log backup, as part of the regular schedule. Is there any other way to issue transaction log backups in SQL Server?

Answer: Prior to SQL Server 2017, we could only issue transaction log backups on a regular interval. SQL Server 2017 introduces a new DMF called sys.dm_db_log_stats. In this DMF, the column logsincelastbackup represents how much log data has been generated since the last transaction log backup. Therefore, we can use this feature in our script and configure transaction log backups based on the size of logs generated since the previous transaction log backup.

Additional resources: SQL Server 2017 transaction log backup improvements Q3. Explain the below error.

Msg 3023, Level 16, State 2, Line 1

Answer: We cannot run an ALTER DATABASE, backup and database shrink command on a database in parallel.

Additional resources: 3023 message Q4. What is a SQL Server database restore?

Answer: A SQL Server database restore is the process of creating a point in time version of the database. We can restore the database backup to a separate server, instance and/or geographical location for these types of failures:

Application failure Server failure Disk failure Database failure Database corruption Research data issue Data corruption Additional resources: SQL Server Restore Options and Commands Tutorial Q5. What are the phases of a SQL Server database restore?

Answer: There are 3 phases of database restore:

Data Copy: This phase involves copying the data, log, and index pages from the database to the backup file. Roll forward or Redo: The redo phase rolls forward that data to the recovery point. In this phase, a database typically has uncommitted transactions and is in an unusable state. Roll back or Undo: In this process, any uncommitted transactions are rolled back. Additional resources: SQL Server Restore Options and Commands Tutorial Q6. What is the RESTORE FILELISTONLY command?

Answer: We can see a list of the database files that were backed up for the specific database. This command returns the logical as well as the physical name of the database and log files, type of file (data file, log file, a Full-Text Catalog or File Stream), filegroup name, file size, first and last LSN of the database backup, differential backup LSN, etc.

Additional Information: SQL Server restore filelistonly Q7. Explain the SQL Server RESTORE HeaderOnly command.

Answer: With the SQL Server RESTORE HEADERONLY command we can see the backup header information for all backup sets on a particular backup device. It returns the backup name, description, backup type, backup compression, the username that performed the backup, database name, version, backup size, LSN details, flag to show copy-only backup, etc.

Additional resources

SQL Server Restore Options and Commands Tutorial Q8. Suppose we have a large backup file placed on the server and we need to identify the source database version, the user who performed the backup from the backup file, etc. How can we do that?

Answer: We can use the SQL Server Restore HeaderOnly command to get this information. The syntax for the Restore HeaderOnly command is:

Restore header-only from disk='backup file path'
Go

We can check the below columns to get the data in the output:

User Name Server Name Database Name Database version Additional resources: SQL Server Restore Options and Commands Tutorial Q9. How can we validate the SQL Server backup?

Answer: We can use the Restore VerifyOnly command to validate the database backup. It checks whether the backup is valid or not. It does not perform a database restore. If the backup is valid, the SQL Server Database Engine returns a success message.

RESTORE VERIFYONLY FROM DISK = ‘Backup File Path';
GO

Viewing all articles
Browse latest Browse all 3160

Trending Articles