SQL Server : Take offline database

EXEC sp_dboption N’mydb’, N’offline’, N’true’\r\nOR\r\nALTER DATABASE [mydb] SET OFFLINE WITH\r\nROLLBACK AFTER 30 SECONDS\r\nOR\r\nALTER DATABASE [mydb] SET OFFLINE WITH\r\nROLLBACK IMMEDIATE

\r\n

    \r\n

  • Using the alter database statement (SQL Server 2k and beyond) is the preferred method.
  • \r\n

  • The rollback after statement will force currently executing statements to rollback after N seconds.
  • \r\n

  • The default is to wait for all currently running transactions to complete and for the sessions to be terminated. Use the rollback immediate clause to rollback transactions immediately.
  • \r\n