Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 restoring database

Author  Topic 

jrahman777
Starting Member

6 Posts

Posted - 2012-07-03 : 14:30:45
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
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2012-07-04 : 01:54:49
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 - 2012-07-04 : 03:52:50
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 - 2012-07-04 : 10:46:04
Thank you both.

jannat rahman
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2012-07-04 : 14:31:17
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
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2012-07-05 : 01:50:18
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
   

- Advertisement -