Wednesday, March 7, 2012

Move db to another drive

I have a 4 gb db running on SQL 7 residing on drive 'd'.
I want to move the db to drive 'e', on the same server.
I see the posts about backup/restore, but they deal
with a different server. Would I use the same
process, only restore to a different drive?yes, but in that case you will have to create a database with the new name
and with the new destination files and once the restore is done you will
have to drop the old database and rename the new with the old one.
Instead of that you can use following method:
You can do it with the help of sp_detach_db and sp_attach_db.
first use the sp_detach_db command to detach the database.
Eg
sp_detach_db 'pubs'
copy pubs_log.ldf / mdf files to the destination drive.
after copying the files, you can use the sp_attach_db stored procedure to
reattach the files to SQL Server with the new location
See more help on this in BOL.
--
-Vishal
"Russell" <rsfuller@.fedex.com> wrote in message
news:0a5301c352c0$0e90b970$a601280a@.phx.gbl...
> I have a 4 gb db running on SQL 7 residing on drive 'd'.
> I want to move the db to drive 'e', on the same server.
> I see the posts about backup/restore, but they deal
> with a different server. Would I use the same
> process, only restore to a different drive?|||Wouldn't it be simpler by just restoring the database to e: specifying "with
move"?
backup database pubs to disk = 'c:\pubs.bak' with init
restore database pubs from disk = 'c:\pubs.bak' with replace,
move 'pubs' to 'e:\pubs.mdf',
move 'pubs_log' to 'e:\pubs_log.ldf'
Richard
"Vishal Parkar" <vgparkar@.hotmail.com> wrote in message
news:egU4VEsUDHA.3312@.tk2msftngp13.phx.gbl...
> yes, but in that case you will have to create a database with the new name
> and with the new destination files and once the restore is done you will
> have to drop the old database and rename the new with the old one.
> Instead of that you can use following method:
> You can do it with the help of sp_detach_db and sp_attach_db.
> first use the sp_detach_db command to detach the database.
> Eg
> sp_detach_db 'pubs'
> copy pubs_log.ldf / mdf files to the destination drive.
> after copying the files, you can use the sp_attach_db stored procedure to
> reattach the files to SQL Server with the new location
> See more help on this in BOL.
> --
> -Vishal
> "Russell" <rsfuller@.fedex.com> wrote in message
> news:0a5301c352c0$0e90b970$a601280a@.phx.gbl...
> > I have a 4 gb db running on SQL 7 residing on drive 'd'.
> > I want to move the db to drive 'e', on the same server.
> > I see the posts about backup/restore, but they deal
> > with a different server. Would I use the same
> > process, only restore to a different drive?
>

No comments:

Post a Comment