Skip to content

Instantly share code, notes, and snippets.

@lski
Created September 6, 2014 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lski/6d12520a6089fc77bff7 to your computer and use it in GitHub Desktop.
Save lski/6d12520a6089fc77bff7 to your computer and use it in GitHub Desktop.
Bring all offline databases back online TSQL 2000
DECLARE @name VARCHAR(50) -- database name
DECLARE db_cursor CURSOR FOR
SELECT name
FROM master.dbo.sysdatabases
where DATABASEPROPERTYEX(name, 'Status') = 'OFFLINE'
ORDER BY 1
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name
WHILE @@FETCH_STATUS = 0
BEGIN
-- Take the Database Online
EXEC ('ALTER DATABASE ' + @name + ' SET ONLINE;');
FETCH NEXT FROM db_cursor INTO @name
END
CLOSE db_cursor
DEALLOCATE db_cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment