MS SQL Server Concepts and Programming Question:
Download Questions PDF

How to set a database state to OFFLINE in MS SQL Server?

Answer:

If you want to move database physical files, you should take the database offline by using the "ALTER DATABASE" statement with the following syntax:

ALTER DATABASE database_name SET OFFLINE

The following tutorial example will bring "GlobalGuideLine" offline:

ALTER DATABASE GlobalGuideLine SET OFFLINE
GO

SELECT name, state_desc from sys.databases
GO
name state_desc
master ONLINE
tempdb ONLINE
model ONLINE
msdb ONLINE
GlobalGuideLine OFFLINE

USE GlobalGuideLine
GO
Msg 942, Level 14, State 4, Line 1
Database 'GlobalGuideLine' cannot be opened because
it is offline.


Download MS SQL Server Interview Questions And Answers PDF

Previous QuestionNext Question
What are database states in MS SQL Server?How to move database physical files in MS SQL Server?