-
Notifications
You must be signed in to change notification settings - Fork 23
/
drop_dbs_in_norestore.sql
42 lines (21 loc) · 1.46 KB
/
drop_dbs_in_norestore.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
USE [master]
GO
Declare @cmd varchar(3000)
Declare @DBNAME varchar(64)
--@dbs = 'MissionFed40,BayFederal,ColonialRLC,CUAnswers,CUCompanies,PATrain,SpaceCoast,Lockheed32,WrightPatt32,McDillAFB,Meriwest32,MidwestLoan32,Visions,Weokie,CornellFingerLake,SFFCU,GTE32,WesCom,Kinecta,Verity,ConstructionLoanCompany,FirstAmerican,AmericanAirlines,MembersMortgage,Travis40,MidwestFinancial,Purdue,Numerica'
DECLARE dbnames_cursor CURSOR FOR SELECT name FROM master.dbo.sysdatabases
WHERE name not in ('dbamaint','master','model','msdb','OPS','PADemoDU','PAMonitoring','PAReporting','PASolutions','ScriptErrors','tempdb','WorkFlowManagementCurrent','WebServiceMaintenance','ViewStateManagementCurrent','TaskManagementCurrent','SecurityManagementCurrent','ReportManagementCurrent','Prod_Logs','PASCAdmin','LoanWizardManagementCurrent','FormsManagementCurrent','DynamicScreenManagementCurrent','DocumentManagementCurrent','DirStructure','DataFieldManagementCurrent','ConditionsManagementCurrent','CacheManagementCurrent','AuditFuture','AuditCurrent')
and (select DATABASEPROPERTYEX(name,'STATUS')) = 'Restoring'
OPEN dbnames_cursor
FETCH NEXT FROM dbnames_cursor INTO @DBNAME
WHILE (@@fetch_status <> -1)
BEGIN
print @DBNAME
Select @cmd = 'IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N''' + @DBNAME + ''')' +
' DROP DATABASE ' + @DBNAME
print @cmd
exec(@cmd)
FETCH NEXT FROM dbnames_cursor INTO @DBNAME
END
CLOSE dbnames_cursor
DEALLOCATE dbnames_cursor