<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://mailnest.com/dbawiki/index.php?action=history&amp;feed=atom&amp;title=Restore_SQL_Server_database</id>
		<title>Restore SQL Server database - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://mailnest.com/dbawiki/index.php?action=history&amp;feed=atom&amp;title=Restore_SQL_Server_database"/>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Restore_SQL_Server_database&amp;action=history"/>
		<updated>2026-04-04T05:53:11Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.29.3</generator>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Restore_SQL_Server_database&amp;diff=1234&amp;oldid=prev</id>
		<title>Stuart at 22:11, 28 April 2014</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Restore_SQL_Server_database&amp;diff=1234&amp;oldid=prev"/>
				<updated>2014-04-28T22:11:20Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&#039;diff-marker&#039; /&gt;
				&lt;col class=&#039;diff-content&#039; /&gt;
				&lt;col class=&#039;diff-marker&#039; /&gt;
				&lt;col class=&#039;diff-content&#039; /&gt;
				&lt;tr style=&#039;vertical-align: top;&#039; lang=&#039;en&#039;&gt;
				&lt;td colspan=&#039;2&#039; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&#039;2&#039; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 22:11, 28 April 2014&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l17&quot; &gt;Line 17:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 17:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;nowiki&lt;/del&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;pre&lt;/ins&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;set nocount on&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;set nocount on&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;set quoted_identifier off&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;set quoted_identifier off&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l118&quot; &gt;Line 118:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 118:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;WHERE permission_name = &amp;#039;VIEW DEFINITION&amp;#039; and class_desc = &amp;#039;database&amp;#039;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;WHERE permission_name = &amp;#039;VIEW DEFINITION&amp;#039; and class_desc = &amp;#039;database&amp;#039;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;ORDER BY USER_NAME(grantee_principal_id)&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;ORDER BY USER_NAME(grantee_principal_id)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;nowiki&lt;/del&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;pre&lt;/ins&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:SQL Server]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:SQL Server]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Restore_SQL_Server_database&amp;diff=72&amp;oldid=prev</id>
		<title>127.0.0.1: Created page with &quot;* First copy the dump from \\spifls07.mon.local\DATA.1013\01_DBdumps\SQL\ to the target SQL Server in ONT * Check the current security settings on the ONT database, use this scri...&quot;</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Restore_SQL_Server_database&amp;diff=72&amp;oldid=prev"/>
				<updated>2011-12-06T19:43:09Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;* First copy the dump from \\spifls07.mon.local\DATA.1013\01_DBdumps\SQL\ to the target SQL Server in ONT * Check the current security settings on the ONT database, use this scri...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;* First copy the dump from \\spifls07.mon.local\DATA.1013\01_DBdumps\SQL\ to the target SQL Server in ONT&lt;br /&gt;
* Check the current security settings on the ONT database, use this script  [[Link List all permission in DB]].&lt;br /&gt;
* Restore over the existing database. Use the GUI interface to setup the restore, check the &amp;#039;with replace&amp;#039; box, then script the statement to a new window.&lt;br /&gt;
* There alter the script to get the following result&lt;br /&gt;
  ALTER DATABASE [DBToRestore] SET Single_user with rollback immediate&lt;br /&gt;
  GO&lt;br /&gt;
  RESTORE DATABASE ...&lt;br /&gt;
* Let the restore do it&amp;#039;s thing&lt;br /&gt;
* When finished, recreate the premission with the above generated script&lt;br /&gt;
* Eventually clean up the MON accounts ...&lt;br /&gt;
* If any SQL accounts are restored, fix them with the following statement&lt;br /&gt;
  exec sp_change_users_login &amp;#039;auto_fix&amp;#039;, &amp;#039;usernametofix&amp;#039;&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
[[Category:SQL Server]]&lt;br /&gt;
[[Category:BackupRestore]]&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
set nocount on&lt;br /&gt;
set quoted_identifier off&lt;br /&gt;
declare @as_ObjectName sysname&lt;br /&gt;
set @as_ObjectName = NULL&lt;br /&gt;
 &lt;br /&gt;
--database owner info&lt;br /&gt;
select &amp;#039;alter authorization on database::[&amp;#039;+db_name()+&amp;#039;] to [&amp;#039;+ suser_sname(owner_sid)+&amp;#039;]&amp;#039;&lt;br /&gt;
AS &amp;#039;--owner of database when script was created&amp;#039;&lt;br /&gt;
from master.sys.databases where name = db_name()&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
--drop and recreate users&lt;br /&gt;
 &lt;br /&gt;
select &amp;#039;-- It is not always necessary to drop and recreate the users it will depend on the circumstances under which you need to run this script&amp;#039;&lt;br /&gt;
 &lt;br /&gt;
select &amp;#039;drop user [&amp;#039; + name + &amp;#039;]&amp;#039; from sys.database_principals&lt;br /&gt;
where principal_id &amp;gt; 4 and owning_principal_id is NULL&lt;br /&gt;
and type != &amp;#039;A&amp;#039;&lt;br /&gt;
order by name&lt;br /&gt;
 &lt;br /&gt;
select &amp;#039;CREATE USER [&amp;#039; + dp.name collate database_default + &amp;#039;] FOR LOGIN [&amp;#039; + sp.name + &amp;#039;]&amp;#039;+&lt;br /&gt;
case dp.type&lt;br /&gt;
when &amp;#039;G&amp;#039; then &amp;#039; &amp;#039;&lt;br /&gt;
else&lt;br /&gt;
&amp;#039; WITH DEFAULT_SCHEMA=[&amp;#039;+dp.default_schema_name + &amp;#039;]&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
as &amp;#039;-- by default Orphaned users will not be recreated&amp;#039;&lt;br /&gt;
from sys.server_principals sp&lt;br /&gt;
inner join sys.database_principals dp on dp.sid = sp.sid&lt;br /&gt;
where dp.principal_id &amp;gt; 4 and dp.owning_principal_id is NULL and sp.name &amp;lt;&amp;gt; &amp;#039;&amp;#039;&lt;br /&gt;
order by dp.name&lt;br /&gt;
 &lt;br /&gt;
-- Recreate the User defined roles&lt;br /&gt;
select &amp;#039;-- server created roles should be added by the correct processes&amp;#039;&lt;br /&gt;
 &lt;br /&gt;
select &amp;#039;CREATE ROLE [&amp;#039;+ name + &amp;#039;] AUTHORIZATION [&amp;#039;+USER_NAME(owning_principal_id)+&amp;#039;]&amp;#039;&lt;br /&gt;
from sys.database_principals&lt;br /&gt;
where name != &amp;#039;public&amp;#039; and type = &amp;#039;R&amp;#039; and is_fixed_role = 0&lt;br /&gt;
 &lt;br /&gt;
-- recreate application roles&lt;br /&gt;
 &lt;br /&gt;
select &amp;#039;CREATE APPLICATION ROLE [&amp;#039;+ name + &amp;#039;] with password = &amp;#039;+QUOTENAME(&amp;#039;insertpwdhere&amp;#039;,&amp;#039;&amp;#039;&amp;#039;&amp;#039;)+&amp;#039; ,default_schema = [&amp;#039;+default_schema_name+&amp;#039;]&amp;#039;&lt;br /&gt;
from sys.database_principals&lt;br /&gt;
where type = &amp;#039;A&amp;#039;&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
-- ADD ROLE MEMBERS&lt;br /&gt;
 &lt;br /&gt;
SELECT &amp;#039;EXEC sp_addrolemember [&amp;#039; + dp.name + &amp;#039;], [&amp;#039; + USER_NAME(drm.member_principal_id) + &amp;#039;] &amp;#039; AS [-- AddRolemembers]&lt;br /&gt;
FROM sys.database_role_members drm&lt;br /&gt;
INNER JOIN sys.database_principals dp ON dp.principal_id = drm.role_principal_id&lt;br /&gt;
where USER_NAME(drm.member_principal_id) != &amp;#039;dbo&amp;#039;&lt;br /&gt;
order by drm.role_principal_id&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
-- CREATE GRANT Object PERMISSIONS SCRIPT&lt;br /&gt;
 &lt;br /&gt;
SELECT replace(state_desc,&amp;#039;_with_grant_option&amp;#039;,&amp;#039;&amp;#039;) + &amp;#039; &amp;#039;+ permission_name + &amp;#039; ON [&amp;#039;&lt;br /&gt;
+ OBJECT_SCHEMA_NAME(major_id) + &amp;#039;].[&amp;#039; + OBJECT_NAME(major_id) + &amp;#039;]&amp;#039;+&lt;br /&gt;
case minor_id&lt;br /&gt;
when 0 then &amp;#039; &amp;#039;&lt;br /&gt;
else&lt;br /&gt;
&amp;#039; ([&amp;#039;+col_name(sys.database_permissions.major_Id, sys.database_permissions.minor_id) + &amp;#039;])&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
+&amp;#039; TO [&amp;#039; + USER_NAME(grantee_principal_id)+&amp;#039;]&amp;#039; +&lt;br /&gt;
case&lt;br /&gt;
when state_desc like &amp;#039;%with_grant_option&amp;#039; then &amp;#039; with grant option&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
&amp;#039; &amp;#039;&lt;br /&gt;
end&lt;br /&gt;
as &amp;#039;-- object/column permissions&amp;#039;&lt;br /&gt;
FROM sys.database_permissions (NOLOCK)&lt;br /&gt;
WHERE class not in (0,3) and major_id = ISNULL(OBJECT_ID(@as_ObjectName), major_id)&lt;br /&gt;
--AND OBJECT_SCHEMA_NAME(major_id) != &amp;#039;SYS&amp;#039;&lt;br /&gt;
ORDER BY USER_NAME(grantee_principal_id),OBJECT_SCHEMA_NAME(major_id), OBJECT_NAME(major_id)&lt;br /&gt;
 &lt;br /&gt;
--SCHEMA permissions&lt;br /&gt;
SELECT replace(state_desc,&amp;#039;_with_grant_option&amp;#039;,&amp;#039;&amp;#039;) + &amp;#039; &amp;#039;+ permission_name + &amp;#039; ON SCHEMA::[&amp;#039;&lt;br /&gt;
+ SCHEMA_NAME(major_id) + &amp;#039;]&amp;#039;+&lt;br /&gt;
+&amp;#039; TO [&amp;#039; + USER_NAME(grantee_principal_id)+&amp;#039;]&amp;#039; +&lt;br /&gt;
case&lt;br /&gt;
when state_desc like &amp;#039;%with_grant_option&amp;#039; then &amp;#039; with grant option&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
&amp;#039; &amp;#039;&lt;br /&gt;
end&lt;br /&gt;
as &amp;#039;-- Schema permissions&amp;#039;&lt;br /&gt;
FROM sys.database_permissions (NOLOCK)&lt;br /&gt;
WHERE class_desc = &amp;#039;SCHEMA&amp;#039;&lt;br /&gt;
ORDER BY USER_NAME(grantee_principal_id),SCHEMA_NAME(major_id)&lt;br /&gt;
 &lt;br /&gt;
SELECT replace(state_desc,&amp;#039;_with_grant_option&amp;#039;,&amp;#039;&amp;#039;) + &amp;#039; &amp;#039;+ permission_name +&lt;br /&gt;
&amp;#039; TO [&amp;#039; + USER_NAME(grantee_principal_id)+&amp;#039;]&amp;#039; +&lt;br /&gt;
case&lt;br /&gt;
when state_desc like &amp;#039;%with_grant_option&amp;#039; then &amp;#039; with grant option&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
&amp;#039; &amp;#039;&lt;br /&gt;
end&lt;br /&gt;
FROM sys.database_permissions (NOLOCK)&lt;br /&gt;
WHERE permission_name = &amp;#039;VIEW DEFINITION&amp;#039; and class_desc = &amp;#039;database&amp;#039;&lt;br /&gt;
ORDER BY USER_NAME(grantee_principal_id)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
[[Category:SQL Server]]&lt;/div&gt;</summary>
		<author><name>127.0.0.1</name></author>	</entry>

	</feed>