Sample Code
-- Create Test Database
Create Database Test
Go
Use Test
Go
-- Create test table
Create Table Test
(
ID Uniqueidentifier Default Newid (),
Summary Varchar ( 200 )
)
-- Full backup database
Backup Database Test To Disk = ' F: \ test. Bak ' With Format
-- Insert the first record to the test table
Insert Into Test Values ( Default , ' First Incremental Backup ' )
-- First Incremental Backup
Backup Database Test To Disk = ' F: \ test_one_diff.diff ' With Format, differential
-- Insert the second record to the TB table
Insert Into Test Values ( Default , ' Second Incremental Backup ' )
-- Second Incremental Backup
Backup Database Test To Disk = ' F: \ test_two_diff.diff ' With Format, differential
-- Now the full backup and the first Incremental Backup are completely restored.
Go
Use Master
-- Full Backup Recovery
Restore Database Test From Disk = ' F: \ test. Bak ' With Replace , Norecovery
-- Restore from the first Incremental Backup
Restore Database Test From Disk = ' F: \ test_one_diff.diff ' With Recovery
Go
Use Test
Go
Select * From Test
-- Now the full backup and the second Incremental Backup are completely restored.
Use Master
-- Full Backup Recovery
Restore Database Test From Disk = ' F: \ test. Bak ' With Replace , Norecovery
-- Second Incremental backup restoration
Restore Database Test From Disk = ' F: \ test_two_diff.diff ' With Recovery
Go
Use Test
Go
Select * From Test
-- Delete Test Database
Go
Use Master
Go
Drop Database Test