Create a new database from a restore file and change primary database file location
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have a SQL Server 2008 database (A) that I want to copy to a new server to use as a copy of previous state (A_BKP) .
I have understood from https://docs.microsoft.com/en-us/sql/relational-databases/backup-restore/restore-a-database-to-a-new-location-sql-server?view=sql-server-2017
That this is possible in later versions but I also want to move the target files from the C: drive to the D:
Is this possible with SQL Server 2008, and what steps would I need to prep the database backup file to import but to the D: drive.?
sql
add a comment |
I have a SQL Server 2008 database (A) that I want to copy to a new server to use as a copy of previous state (A_BKP) .
I have understood from https://docs.microsoft.com/en-us/sql/relational-databases/backup-restore/restore-a-database-to-a-new-location-sql-server?view=sql-server-2017
That this is possible in later versions but I also want to move the target files from the C: drive to the D:
Is this possible with SQL Server 2008, and what steps would I need to prep the database backup file to import but to the D: drive.?
sql
add a comment |
I have a SQL Server 2008 database (A) that I want to copy to a new server to use as a copy of previous state (A_BKP) .
I have understood from https://docs.microsoft.com/en-us/sql/relational-databases/backup-restore/restore-a-database-to-a-new-location-sql-server?view=sql-server-2017
That this is possible in later versions but I also want to move the target files from the C: drive to the D:
Is this possible with SQL Server 2008, and what steps would I need to prep the database backup file to import but to the D: drive.?
sql
I have a SQL Server 2008 database (A) that I want to copy to a new server to use as a copy of previous state (A_BKP) .
I have understood from https://docs.microsoft.com/en-us/sql/relational-databases/backup-restore/restore-a-database-to-a-new-location-sql-server?view=sql-server-2017
That this is possible in later versions but I also want to move the target files from the C: drive to the D:
Is this possible with SQL Server 2008, and what steps would I need to prep the database backup file to import but to the D: drive.?
sql
sql
edited Jan 4 at 12:55
SystemsInCode
asked Jan 4 at 11:59
SystemsInCodeSystemsInCode
1088
1088
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
If you want to "move" your DB to another server first you need to DETACH your DB.
Instruction is :
- Open SSMS
- Choose your db which you want to move.
- Right Click --> Tasks --> Detach
- Detach Database pop-up will be shown.
- Before you detach your database you need to sure no one connected to database. Check the "Message" column. It will show you if there are connections. If there are connections but you still want to Detach your database you can click "Drop Connections" check box.
- Press Ok
Now you can move your database files (MDF,LDF,FDF) to another location.
To ATTACH your database to new server :
- Connect to new server using SSMS
- Right Click on Databases and Click Attach
- Press Add button in middle right.
- Choose the MDF (Main DB File) file which you moved and press ok.
- Press ok.
If you want to restore database backup to new server as NEW database :
- Connect to new server using SSMS
- Right Click on Databases and Click Restore Database
- Click Device on top right under the Source and add your backup file
- If you want to change your db name you can update it on Destination --> Database section.
- Go to Files tab on top left
- You can see file locations there. if you want to change the location simply you can update it on "Restore As" column.
- Press Ok.
or use following script :
USE [master]
RESTORE DATABASE [A]
FROM DISK = N'<yourbackuplocationA_BKP.bak>'
WITH FILE = 1,
MOVE N'A_Main' TO N'<new location for MAIN database file<file name>.mdf>',
MOVE N'A_Log' TO N'<new location for LOG database file<file name>.ldf>',
NOUNLOAD,
STATS = 5
GO
If you want to restore database backup to new server to EXISTING database :
ALTER DATABASE [A] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
RESTORE DATABASE [A]
FROM DISK = '<yourbackuplocationA_BKP.bak>' WITH FILE = 1,
MOVE N'A_Main' TO N'<new location for MAIN database file<file name>.mdf>',
MOVE N'A_Log' TO N'<new location for LOG database file<file name>.ldf>',
NOUNLOAD,
STATS = 5
ALTER DATABASE [A] SET MULTI_USER
Sorry just copy is fine
– SystemsInCode
Jan 4 at 12:56
1
@SystemsInCode You can find MOVE and COPY solutions in the answer. I also added instruction for the copy if you don't want to use script.
– Zeki Gumus
Jan 4 at 13:03
Worked great with ssms gui, thanks
– SystemsInCode
Jan 4 at 15:34
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54038565%2fcreate-a-new-database-from-a-restore-file-and-change-primary-database-file-locat%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you want to "move" your DB to another server first you need to DETACH your DB.
Instruction is :
- Open SSMS
- Choose your db which you want to move.
- Right Click --> Tasks --> Detach
- Detach Database pop-up will be shown.
- Before you detach your database you need to sure no one connected to database. Check the "Message" column. It will show you if there are connections. If there are connections but you still want to Detach your database you can click "Drop Connections" check box.
- Press Ok
Now you can move your database files (MDF,LDF,FDF) to another location.
To ATTACH your database to new server :
- Connect to new server using SSMS
- Right Click on Databases and Click Attach
- Press Add button in middle right.
- Choose the MDF (Main DB File) file which you moved and press ok.
- Press ok.
If you want to restore database backup to new server as NEW database :
- Connect to new server using SSMS
- Right Click on Databases and Click Restore Database
- Click Device on top right under the Source and add your backup file
- If you want to change your db name you can update it on Destination --> Database section.
- Go to Files tab on top left
- You can see file locations there. if you want to change the location simply you can update it on "Restore As" column.
- Press Ok.
or use following script :
USE [master]
RESTORE DATABASE [A]
FROM DISK = N'<yourbackuplocationA_BKP.bak>'
WITH FILE = 1,
MOVE N'A_Main' TO N'<new location for MAIN database file<file name>.mdf>',
MOVE N'A_Log' TO N'<new location for LOG database file<file name>.ldf>',
NOUNLOAD,
STATS = 5
GO
If you want to restore database backup to new server to EXISTING database :
ALTER DATABASE [A] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
RESTORE DATABASE [A]
FROM DISK = '<yourbackuplocationA_BKP.bak>' WITH FILE = 1,
MOVE N'A_Main' TO N'<new location for MAIN database file<file name>.mdf>',
MOVE N'A_Log' TO N'<new location for LOG database file<file name>.ldf>',
NOUNLOAD,
STATS = 5
ALTER DATABASE [A] SET MULTI_USER
Sorry just copy is fine
– SystemsInCode
Jan 4 at 12:56
1
@SystemsInCode You can find MOVE and COPY solutions in the answer. I also added instruction for the copy if you don't want to use script.
– Zeki Gumus
Jan 4 at 13:03
Worked great with ssms gui, thanks
– SystemsInCode
Jan 4 at 15:34
add a comment |
If you want to "move" your DB to another server first you need to DETACH your DB.
Instruction is :
- Open SSMS
- Choose your db which you want to move.
- Right Click --> Tasks --> Detach
- Detach Database pop-up will be shown.
- Before you detach your database you need to sure no one connected to database. Check the "Message" column. It will show you if there are connections. If there are connections but you still want to Detach your database you can click "Drop Connections" check box.
- Press Ok
Now you can move your database files (MDF,LDF,FDF) to another location.
To ATTACH your database to new server :
- Connect to new server using SSMS
- Right Click on Databases and Click Attach
- Press Add button in middle right.
- Choose the MDF (Main DB File) file which you moved and press ok.
- Press ok.
If you want to restore database backup to new server as NEW database :
- Connect to new server using SSMS
- Right Click on Databases and Click Restore Database
- Click Device on top right under the Source and add your backup file
- If you want to change your db name you can update it on Destination --> Database section.
- Go to Files tab on top left
- You can see file locations there. if you want to change the location simply you can update it on "Restore As" column.
- Press Ok.
or use following script :
USE [master]
RESTORE DATABASE [A]
FROM DISK = N'<yourbackuplocationA_BKP.bak>'
WITH FILE = 1,
MOVE N'A_Main' TO N'<new location for MAIN database file<file name>.mdf>',
MOVE N'A_Log' TO N'<new location for LOG database file<file name>.ldf>',
NOUNLOAD,
STATS = 5
GO
If you want to restore database backup to new server to EXISTING database :
ALTER DATABASE [A] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
RESTORE DATABASE [A]
FROM DISK = '<yourbackuplocationA_BKP.bak>' WITH FILE = 1,
MOVE N'A_Main' TO N'<new location for MAIN database file<file name>.mdf>',
MOVE N'A_Log' TO N'<new location for LOG database file<file name>.ldf>',
NOUNLOAD,
STATS = 5
ALTER DATABASE [A] SET MULTI_USER
Sorry just copy is fine
– SystemsInCode
Jan 4 at 12:56
1
@SystemsInCode You can find MOVE and COPY solutions in the answer. I also added instruction for the copy if you don't want to use script.
– Zeki Gumus
Jan 4 at 13:03
Worked great with ssms gui, thanks
– SystemsInCode
Jan 4 at 15:34
add a comment |
If you want to "move" your DB to another server first you need to DETACH your DB.
Instruction is :
- Open SSMS
- Choose your db which you want to move.
- Right Click --> Tasks --> Detach
- Detach Database pop-up will be shown.
- Before you detach your database you need to sure no one connected to database. Check the "Message" column. It will show you if there are connections. If there are connections but you still want to Detach your database you can click "Drop Connections" check box.
- Press Ok
Now you can move your database files (MDF,LDF,FDF) to another location.
To ATTACH your database to new server :
- Connect to new server using SSMS
- Right Click on Databases and Click Attach
- Press Add button in middle right.
- Choose the MDF (Main DB File) file which you moved and press ok.
- Press ok.
If you want to restore database backup to new server as NEW database :
- Connect to new server using SSMS
- Right Click on Databases and Click Restore Database
- Click Device on top right under the Source and add your backup file
- If you want to change your db name you can update it on Destination --> Database section.
- Go to Files tab on top left
- You can see file locations there. if you want to change the location simply you can update it on "Restore As" column.
- Press Ok.
or use following script :
USE [master]
RESTORE DATABASE [A]
FROM DISK = N'<yourbackuplocationA_BKP.bak>'
WITH FILE = 1,
MOVE N'A_Main' TO N'<new location for MAIN database file<file name>.mdf>',
MOVE N'A_Log' TO N'<new location for LOG database file<file name>.ldf>',
NOUNLOAD,
STATS = 5
GO
If you want to restore database backup to new server to EXISTING database :
ALTER DATABASE [A] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
RESTORE DATABASE [A]
FROM DISK = '<yourbackuplocationA_BKP.bak>' WITH FILE = 1,
MOVE N'A_Main' TO N'<new location for MAIN database file<file name>.mdf>',
MOVE N'A_Log' TO N'<new location for LOG database file<file name>.ldf>',
NOUNLOAD,
STATS = 5
ALTER DATABASE [A] SET MULTI_USER
If you want to "move" your DB to another server first you need to DETACH your DB.
Instruction is :
- Open SSMS
- Choose your db which you want to move.
- Right Click --> Tasks --> Detach
- Detach Database pop-up will be shown.
- Before you detach your database you need to sure no one connected to database. Check the "Message" column. It will show you if there are connections. If there are connections but you still want to Detach your database you can click "Drop Connections" check box.
- Press Ok
Now you can move your database files (MDF,LDF,FDF) to another location.
To ATTACH your database to new server :
- Connect to new server using SSMS
- Right Click on Databases and Click Attach
- Press Add button in middle right.
- Choose the MDF (Main DB File) file which you moved and press ok.
- Press ok.
If you want to restore database backup to new server as NEW database :
- Connect to new server using SSMS
- Right Click on Databases and Click Restore Database
- Click Device on top right under the Source and add your backup file
- If you want to change your db name you can update it on Destination --> Database section.
- Go to Files tab on top left
- You can see file locations there. if you want to change the location simply you can update it on "Restore As" column.
- Press Ok.
or use following script :
USE [master]
RESTORE DATABASE [A]
FROM DISK = N'<yourbackuplocationA_BKP.bak>'
WITH FILE = 1,
MOVE N'A_Main' TO N'<new location for MAIN database file<file name>.mdf>',
MOVE N'A_Log' TO N'<new location for LOG database file<file name>.ldf>',
NOUNLOAD,
STATS = 5
GO
If you want to restore database backup to new server to EXISTING database :
ALTER DATABASE [A] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
RESTORE DATABASE [A]
FROM DISK = '<yourbackuplocationA_BKP.bak>' WITH FILE = 1,
MOVE N'A_Main' TO N'<new location for MAIN database file<file name>.mdf>',
MOVE N'A_Log' TO N'<new location for LOG database file<file name>.ldf>',
NOUNLOAD,
STATS = 5
ALTER DATABASE [A] SET MULTI_USER
edited Jan 4 at 13:02
answered Jan 4 at 12:54
Zeki GumusZeki Gumus
1,445313
1,445313
Sorry just copy is fine
– SystemsInCode
Jan 4 at 12:56
1
@SystemsInCode You can find MOVE and COPY solutions in the answer. I also added instruction for the copy if you don't want to use script.
– Zeki Gumus
Jan 4 at 13:03
Worked great with ssms gui, thanks
– SystemsInCode
Jan 4 at 15:34
add a comment |
Sorry just copy is fine
– SystemsInCode
Jan 4 at 12:56
1
@SystemsInCode You can find MOVE and COPY solutions in the answer. I also added instruction for the copy if you don't want to use script.
– Zeki Gumus
Jan 4 at 13:03
Worked great with ssms gui, thanks
– SystemsInCode
Jan 4 at 15:34
Sorry just copy is fine
– SystemsInCode
Jan 4 at 12:56
Sorry just copy is fine
– SystemsInCode
Jan 4 at 12:56
1
1
@SystemsInCode You can find MOVE and COPY solutions in the answer. I also added instruction for the copy if you don't want to use script.
– Zeki Gumus
Jan 4 at 13:03
@SystemsInCode You can find MOVE and COPY solutions in the answer. I also added instruction for the copy if you don't want to use script.
– Zeki Gumus
Jan 4 at 13:03
Worked great with ssms gui, thanks
– SystemsInCode
Jan 4 at 15:34
Worked great with ssms gui, thanks
– SystemsInCode
Jan 4 at 15:34
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54038565%2fcreate-a-new-database-from-a-restore-file-and-change-primary-database-file-locat%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown