Skip to content

Instantly share code, notes, and snippets.

@erichexter
Created August 17, 2017 11:42
Show Gist options
  • Save erichexter/ad6cdff175c415424d81958b66d3489c to your computer and use it in GitHub Desktop.
Save erichexter/ad6cdff175c415424d81958b66d3489c to your computer and use it in GitHub Desktop.
use master
go
declare @dbnames nvarchar(max)
declare @statement nvarchar(max)
set @dbnames = ''
set @statement = ''
select @dbnames = @dbnames + ',[' + name + ']' from sys.databases where name like 'qs_a%' or name like 'qs_int%' or name like 'qs_ui%'
if len(@dbnames) = 0
begin
print 'no databases to drop'
end
else
begin
set @statement = 'drop database ' + substring(@dbnames, 2, len(@dbnames))
print @statement
exec sp_executesql @statement
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment