Solved

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

Posted on 2012-03-30
6
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 25

Accepted Solution

by:
TempDBA earned 125 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 250 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 23

Assisted Solution

by:Racim BOUDJAKDJI
Racim BOUDJAKDJI earned 250 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 125 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

636 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