Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. USE master
  2. GO
  3.  
  4. CREATE DATABASE sampledatabase
  5. GO
  6.  
  7. ALTER DATABASE sampledatabase SET RECOVERY FULL
  8.  
  9. USE sampledatabase
  10. GO
  11.  
  12. CREATE TABLE SampleData
  13. (
  14. id INT PRIMARY KEY ,
  15. col1 tinyint NOT NULL ,
  16. col2 BIT NOT NULL ,
  17. col3 BIT NOT NULL ,
  18. RegistrationDate DATETIME NOT NULL
  19. )
  20.  
  21. GO
  22.  
  23. INSERT [dbo].[SampleData] ([id],[col1], [col2], [col3], [RegistrationDate])
  24. VALUES (94495, 25, 1, 1, '02-03-2008')
  25.  
  26. INSERT [dbo].[SampleData] ([id],[col1], [col2], [col3], [RegistrationDate])
  27. VALUES (94496, 26, 1, 1, '02-04-2008')
  28.  
  29. INSERT [dbo].[SampleData] ([id],[col1], [col2], [col3], [RegistrationDate])
  30. VALUES (94497, 27, 1, 1, '02-05-2008')
  31.  
  32. BACKUP DATABASE sampledatabase TO DISK ='C:\20462\sampledata_full.bak' WITH INIT,STATS;
  33. GO
  34.  
  35. INSERT [dbo].[SampleData] ([id],[col1], [col2], [col3], [RegistrationDate])
  36. VALUES (94498, 29, 1, 1, '02-03-2009')
  37.  
  38. INSERT [dbo].[SampleData] ([id],[col1], [col2], [col3], [RegistrationDate])
  39. VALUES (94499, 28, 1, 1, '02-04-2009')
  40.  
  41. INSERT [dbo].[SampleData] ([id],[col1], [col2], [col3], [RegistrationDate])
  42. VALUES (94500, 30, 1, 1, '02-05-2009')
  43.  
  44. SELECT * FROM sampledata
  45.  
  46. BACKUP DATABASE sampledatabase TO DISK = 'C:\20462\sampledata_diff.bak' WITH DIFFERENTIAL
  47. GO
  48.  
  49. INSERT [dbo].[SampleData] ([id],[col1], [col2], [col3], [RegistrationDate])
  50. VALUES (94501, 29, 1, 1, '02-03-2010')
  51.  
  52. INSERT [dbo].[SampleData] ([id],[col1], [col2], [col3], [RegistrationDate])
  53. VALUES (94502, 28, 1, 1, '02-04-2010')
  54.  
  55. INSERT [dbo].[SampleData] ([id],[col1], [col2], [col3], [RegistrationDate])
  56. VALUES (94503, 30, 1, 1, '02-05-2010')
  57.  
  58. BACKUP LOG sampledatabase TO DISK ='C:\20462\sampledata_Log1.bak' WITH INIT,STATS;
  59. GO
  60.  
  61. INSERT [dbo].[SampleData] ([id],[col1], [col2], [col3], [RegistrationDate])
  62. VALUES (94505, 29, 1, 1, '02-08-2010')
  63.  
  64. INSERT [dbo].[SampleData] ([id],[col1], [col2], [col3], [RegistrationDate])
  65. VALUES (94506, 28, 1, 1, '02-09-2010')
  66.  
  67. INSERT [dbo].[SampleData] ([id],[col1], [col2], [col3], [RegistrationDate])
  68. VALUES (94507, 30, 1, 1, '12-05-2010')
  69.  
  70. BACKUP LOG sampledatabase TO DISK ='C:\20462\sampledata_Log2.bak' WITH INIT,STATS;
  71. GO
  72.  
  73. INSERT [dbo].[SampleData] ([id],[col1], [col2], [col3], [RegistrationDate])
  74. VALUES (94508, 29, 1, 1, '02-28-2011')
  75.  
  76. INSERT [dbo].[SampleData] ([id],[col1], [col2], [col3], [RegistrationDate])
  77. VALUES (94510, 28, 1, 1, '02-27-2011')
  78.  
  79. INSERT [dbo].[SampleData] ([id],[col1], [col2], [col3], [RegistrationDate])
  80. VALUES (94511, 30, 1, 1, '12-12-2011')
  81.  
  82. BACKUP LOG sampledatabase TO DISK ='C:\20462\sampledata_Log3.bak' WITH INIT,STATS;
  83. GO
  84.  
  85. select * from dbo.SampleData
  86.  
  87. INSERT [dbo].[SampleData] ([id],[col1], [col2], [col3], [RegistrationDate])
  88. VALUES (100000, 30, 1, 1, '12-02-2012')
  89.  
  90. SELECT TOP 5*
  91. FROM sampledata
  92. ORDER BY id DESC
  93.  
  94. USE master
  95. GO
  96.  
  97. ALTER DATABASE sampledatabase SET OFFLINE WITH NO_WAIT;
  98.  
  99. --simulate the disaster by deleting the .mdf file
  100.  
  101. ALTER DATABASE sampledatabase SET ONLINE
  102.  
  103. --this will result in a nasty error since there is no database file
  104.  
  105. BACKUP LOG sampledatabase TO DISK ='C:\20462\sampledata_TailLog.bak' WITH INIT,NO_TRUNCATE;
  106. GO
  107.  
  108. RESTORE DATABASE sampledatabase FROM DISK='C:\20462\sampledata_full.bak' WITH NORECOVERY, REPLACE
  109. RESTORE DATABASE sampledatabase FROM DISK='C:\20462\sampledata_diff.bak' WITH NORECOVERY
  110.  
  111. RESTORE DATABASE sampledatabase FROM DISK='C:\20462\sampledata_Log1.bak' WITH NORECOVERY
  112.  
  113. RESTORE DATABASE sampledatabase FROM DISK='C:\20462\sampledata_Log2.bak' WITH NORECOVERY
  114.  
  115. RESTORE DATABASE sampledatabase FROM DISK='C:\20462\sampledata_Log3.bak' WITH NORECOVERY
  116.  
  117. RESTORE DATABASE sampledatabase FROM DISK='C:\20462\sampledata_TailLog.bak' WITH NORECOVERY
  118.  
  119. RESTORE DATABASE sampledatabase WITH RECOVERY
  120.  
  121. USE sampledatabase
  122. GO
  123.  
  124. SELECT *
  125. FROM sampledata
  126. ORDER BY id DESC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement