Tüm DB leri offline-Online Yapmak

-- Tüm dbleri online yap(sistem dbleri hariç)
BEGIN
DECLARE @db sysname, @q varchar(max);
DECLARE cur_db CURSOR FOR
SELECT name FROM sys.databases WHERE database_id>4 and state=6 order by name;
OPEN cur_db;
WHILE 1=1
BEGIN
FETCH NEXT FROM cur_db INTO @db;
IF @@FETCH_STATUS <> 0
BREAK;
SET @q = N'ALTER DATABASE [' + @db + N'] SET ONLINE WITH NO_WAIT';
---- EXEC(@q);
Print(@q); 
END;
CLOSE cur_db;
DEALLOCATE cur_db;
END;


-- Tüm dbleri offline yap(sistem dbleri hariç)
BEGIN
DECLARE @db sysname, @q varchar(max);
DECLARE cur_db CURSOR FOR
SELECT name FROM sys.databases WHERE database_id>4 and state=0 order by name;
OPEN cur_db;
WHILE 1=1
BEGIN
FETCH NEXT FROM cur_db INTO @db;
IF @@FETCH_STATUS <> 0
BREAK;
SET @q = N'ALTER DATABASE [' + @db + N'] SET OFFLINE WITH NO_WAIT';
---- EXEC(@q);
Print(@q); 
END;
CLOSE cur_db;
DEALLOCATE cur_db;
END;

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir