Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Drop all Databases (+the option to exclude one)

By Kecerdikan,

I made this Query because we fix databases localy on a workstation (we have no sql server) but when backup up the server they need to be deleted localy that could sometimes take a while.
U can run this Query from the QA or ad it as a Job it's possible to run it from an executable.

A little more about Keepdb and Previewdb.
If you want/need to keep more databases just add the line:
AND name NOT IN ('Keepdb1','Keepdb2','Keepdb3')
If you want/need to keep just one add the line:
AND name NOT IN ('Keepdb1')
Type the line right below this line:
SELECT name FROM sysdatabases WHERE sid 0x01

Previewdb: It means that you can see which databases will be dropped make sure that it looks like this
-- before: exec sp_executesql @SQL
print @SQL
If you happy with the result you can just remove the -- and print @SQL
Happy dropping

Total article views: 497 | Views in the last 30 days: 2
 
Related Articles
FORUM

Database

Database

FORUM

Database Sync

Database

FORUM

Database suspect

Database

FORUM
FORUM

Database Synchronization

Database Synchronization

Tags
miscellaneous    
 
Contribute