Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

What's the fastest way to copy a database on the same server?

Posted on 2012-03-30
6
Medium Priority
?
292 Views
Last Modified: 2012-04-14
If I want to copy a database test_db1 to a same database server with a different name test_db2, what would be the fast way to do it?

Can I use features like Log Shipping or Transactional Replication on the same database server?

Thanks.
0
Comment
Question by:thomaszhwang
6 Comments
 
LVL 25

Accepted Solution

by:
TempDBA earned 375 total points
ID: 37788229
Backup the database and restore it with different name. That is the easiest and fastest way I guess.
0
 

Author Comment

by:thomaszhwang
ID: 37788391
Can I specify a different database file path when I restore, since if the original database is still there, you cannot just restore the database without specifying a new file path, right?  If so, what T-SQL command should I use?  Thanks.
0
 
LVL 23

Assisted Solution

by:Racim BOUDJAKDJI
Racim BOUDJAKDJI earned 750 total points
ID: 37789478
<<Can I specify a different database file path when I restore, since if the original database is still there>>
when restoring forget about the old database files and old database.  Simply restore the new database with a new name and use the WITH MOVE instruction to assign a new name for the files...For more info,read the below link on how using RESTORE DATABASE instruction WITH MOVE option...

http://msdn.microsoft.com/en-us/library/ms186858.aspx
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 23

Assisted Solution

by:Racim BOUDJAKDJI
Racim BOUDJAKDJI earned 750 total points
ID: 37789483
<<Can I use features like Log Shipping or Transactional Replication on the same database server?>>
Yes.  But it has little or no value.  If you want to keep a READ ONLY copy you can use database snapshots
0
 
LVL 32

Assisted Solution

by:Brendt Hess
Brendt Hess earned 375 total points
ID: 37789682
A generalized restore statement for a simple database backup with only one data file and one log file involved would be like this:

RESTORE DATABASE MyTestDB
FROM DISK='X:\Backups\MyDB.BAK'
WITH Recovery, Replace,
MOVE 'MyDB_data' TO 'X:\SQLData\MyTestDB.mdf',
MOVE 'MyDB_log' TO 'X:\SQLLogs\MyTestLog.ldf',

Where:
MyTestDB is the new database name to use
DISK='...' is the physical location of the backup file on disk
WITH x is the list of options to use - Recovery, Replace is my personal standard pair.  See BoL for more info
MOVE definition
'MyDB_x' is the logical filename being discussed.  Logical filenames can be recovered by executing RESTORE FILELISTONLY from DISK='...'
TO '...' is the physical destination and filename to be used.  You can restore to the same physical location as the original files are in if you rename the resulting files.
0
 

Author Closing Comment

by:thomaszhwang
ID: 37847503
Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how the fundamental information of how to create a table.

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question