65.9K
CodeProject is changing. Read more.
Home

How to Make Database Offline or Online

starIconstarIconstarIconstarIconstarIcon

5.00/5 (10 votes)

Aug 20, 2010

CPOL
viewsIcon

142881

This post will show you how to make database offline or online.

Database is made offline to move its physical files. There can be many ways to make a database offline. But there are three main methods which are used frequently to make the database offline. These methods are given below:

1. With the Help of Alter Database Command

We can make the database offline or online with the help of the Alter database command. The Alter Database command to make the database offline is:

ALTER DATABASE database name SET Offline

If we want to make the database online, we can use the following Alter Database command:

ALTER DATABASE database name SET Online

2. With the Help of the Db_options

We can also use the db_options command to make a database offline or online. To make a database offline, we can use the following command:

sp_dboption databasename ,'offline',true

To make the database online, we can use the following command:

sp_dboption databasename ,'offline',false

3. With the Help of SQL Server Management Studio

We can also use the SQL Server Management Studio to make a database offline as shown in the given figure. To make database offline, we have to follow the step shown in figure 1 and to bring back the database online, we needed to follow the step shown in figure 2:

Figure 1

Figure 2