SQL Server database can be made OFFLINE by running the below SQL statement.
If there are any critical or important transactions running then it's recommended to let them complete first and then run the below queries down.
USE [master];
GO
--Disconnect all existing sessions.
ALTER DATABASE SampleDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
--Change database into OFFLINE mode.
ALTER DATABASE SampleDB SET OFFLINE
Now your database has moved to offline mode.
=>If incase set single user doesn't work, use the below deadlock priority high command
SET DEADLOCK_PRIORITY HIGH
GO
ALTER DATABASE SampleDB SET MULTI_USER WITH ROLLBACK IMMEDIATE
GO
How do we bring back our database online again?
Once we are done with updating the physical file names, the next step is to bring the database ONLINE.
Run the below SQL statement to bring the target database ONLINE.
ALTER DATABASE SampleDB SET ONLINE
Go
ALTER DATABASE SampleDB SET MULTI_USER
Go
No comments:
Post a Comment