views:

1677

answers:

2

Hi folks,

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?

+4  A: 
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
Mitch Wheat
+2  A: 

Here's a note that just might be very usefull to you : It's almost always possible to see what the GUI is doing TSQLwise behind the scenes.

c : http://www.mssqltips.com/tip.asp?tip=1505

Peter
Nod Peter - i use that button (to grab scripts) all the time ... a good example of that is when i wish to change the table structure/schema, and it takes more than 30 seconds (default wait time before a timeout error is raised) .. so i need to grab the change script and run it manually.
Pure.Krome