The only way to do that is to back up the database files to disk and restore them.
eg:
/*
back up the database through SQL statements
*/
BACKUP DATABASE mydb
to DISK = ' C:dbbackmydb.bak '
--Here Specify the path and filename that you want to back up the database, and note that the path's folder must have been created. The file name can be marked with a date
/*
restore the database through SQL statements
*/
Use master
RESTORE DATABASE mydb
from disk= ' C:dbbackmydb.bak '
with REPLACE
Note: Most of the time you cannot restore directly because the data is not open exclusively. You might use the following procedure
--kill the connection to access a database
CREATE PROC killspid (@DBName varchar)
as
BEGIN
DECLARE @SQL varchar
DECLARE @SPID int
SET @SQL = ' DECLARE currentid CURSOR for
SELECT spid from sysprocesses WHERE dbid=db_id (' + @DBName + ') '
FETCH NEXT from CurrentID into @SPID
While @ @FETCH_STATUS <>-1
BEGIN
exec (' KILL ' + @SPID)
FETCH NEXT from CurrentID into @SPID
End
Close CurrentID
deallocate CurrentID
End
Single user action database is best used when killing users
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.