Monday, 6 June 2011

Restoring a SQL database with active users

Sometimes it is necessary to restore a database that has users currently active inside it. Use the following SQL in order to achieve this...

USE [master]
GO
ALTER DATABASE [myDatabaseName] SET  SINGLE_USER WITH ROLLBACK IMMEDIATE
GO

RESTORE DATABASE [myDatabaseName] FROM  DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\myDatabaseName.bak' WITH  FILE = 1,  NOUNLOAD,  REPLACE,  STATS = 10
GO


USE [master]
GO
ALTER DATABASE [myDatabaseName] SET  MULTI_USER WITH ROLLBACK IMMEDIATE
GO

1 comment:

  1. Thanks for sharing the nice video. Here is the tool would be the the user in SQL Database Recovery and restore Process. No technical skill required.

    http://www.recoverfilesdata.com/sql-database-mdf-recovery.html

    Thanks

    ReplyDelete

How to find the last interactive logons in Windows using PowerShell

Use the following powershell script to find the last users to login to a box since a given date, in this case the 21st April 2022 at 12pm un...