Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Script to take a Microsoft Sql database online or offline?

If I wish to take an MS Sql 2008 offline or online, I need to use the GUI -> DB-Tasks-Take Online or Take Offline.

Can this be done with some sql script?

like image 662
Pure.Krome Avatar asked May 11 '09 07:05

Pure.Krome


1 Answers

ALTER DATABASE database-name SET OFFLINE

If you run the ALTER DATABASE command whilst users or processes are connected, but you do not wish the command to be blocked, you can execute the statement with the NO_WAIT option. This causes the command to fail with an error.

ALTER DATABASE database-name SET OFFLINE WITH NO_WAIT

Corresponding online:

ALTER DATABASE database-name SET ONLINE
like image 62
Mitch Wheat Avatar answered Oct 25 '22 17:10

Mitch Wheat