SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 restoring database
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jrahman777
Starting Member

6 Posts

Posted - 07/03/2012 :  14:30:45  Show Profile  Reply with Quote
I have a question:
While the database is online can we restore the same database over? What happens if we don't use any parameters like overwrite existing database or something?

Any reply will be appreciated.

jannat rahman

jackv
Flowing Fount of Yak Knowledge

United Kingdom
1767 Posts

Posted - 07/04/2012 :  01:54:49  Show Profile  Visit jackv's Homepage  Reply with Quote
Read up on the RESTORE..WITH REPLACE option. Basically , will allow an overwrite over an existing db.

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 07/04/2012 :  03:52:50  Show Profile  Reply with Quote
umm..you can't

you have to kick everyone out and set the db to single user mode


WHY?

Go to Top of Page

jrahman777
Starting Member

6 Posts

Posted - 07/04/2012 :  10:46:04  Show Profile  Reply with Quote
Thank you both.

jannat rahman
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

USA
6997 Posts

Posted - 07/04/2012 :  14:31:17  Show Profile  Reply with Quote
Or, you can just drop the database before running the restore.

Makes things simpler because no one can be connected to a database that doesn't exist.
use master

-- Set database offline to kick everyone out
alter database [MyDatabase] set offline with rollback immediate

-- Set database online before dropping it because database files
-- are only deleted when database is dropped while it is online. 
alter database [MyDatabase] set online with rollback immediate

drop database [MyDatabase]

restore database [MyDatabase]
... rest of restore command ...








CODO ERGO SUM
Go to Top of Page

jackv
Flowing Fount of Yak Knowledge

United Kingdom
1767 Posts

Posted - 07/05/2012 :  01:50:18  Show Profile  Visit jackv's Homepage  Reply with Quote
Added to my earlier RESTORE..WITH REPLACE , for extra clarity - kill existing connections first,

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000