Thursday, March 29, 2012

Copy of a database with new filenames

I have database A on files A.mdf and A.ldf
Using sp_detach_db and sp_attach_db I can get
database B on files A.mdf and A.ldf
Is there a way to get database B on B.mdf and B.ldf
not going through the copying of individual objects.
Thanks in advance
SergeiHi,
1. Backup the database A (backup database A to disk='c:\a_db.bak' with init
2. Restore database B from disk='C:\a_db.bak' with move 'logfilename' to
'path\b.mdf',
move 'loglogname' to 'path\b.ldf'
Replace path with your actual path name.
Thanks
Hari
MCDBA
"Sergei" <sergei@.kbotd.ru> wrote in message
news:#y#LzBA3DHA.560@.TK2MSFTNGP11.phx.gbl...
quote:

> I have database A on files A.mdf and A.ldf
> Using sp_detach_db and sp_attach_db I can get
> database B on files A.mdf and A.ldf
> Is there a way to get database B on B.mdf and B.ldf
> not going through the copying of individual objects.
> Thanks in advance
> Sergei
|||Check books on line for the backup with MOVE to statement, it's straight
forward and useful
Regards,
Dandy Weyn
MCSE, MCSA, MCDBA, MCT
www.dandyman.net
"Sergei" <sergei@.kbotd.ru> wrote in message
news:%23y%23LzBA3DHA.560@.TK2MSFTNGP11.phx.gbl...
quote:

> I have database A on files A.mdf and A.ldf
> Using sp_detach_db and sp_attach_db I can get
> database B on files A.mdf and A.ldf
> Is there a way to get database B on B.mdf and B.ldf
> not going through the copying of individual objects.
> Thanks in advance
> Sergei
|||To add to the other responses, you can also rename the file to the desired
names before the attach.
Hope this helps.
Dan Guzman
SQL Server MVP
"Sergei" <sergei@.kbotd.ru> wrote in message
news:%23y%23LzBA3DHA.560@.TK2MSFTNGP11.phx.gbl...
quote:

> I have database A on files A.mdf and A.ldf
> Using sp_detach_db and sp_attach_db I can get
> database B on files A.mdf and A.ldf
> Is there a way to get database B on B.mdf and B.ldf
> not going through the copying of individual objects.
> Thanks in advance
> Sergei

No comments:

Post a Comment