declare @dbname sysname
declare tb cursor local for select name from sysdatabases where name like 'db_%'
open tb
fetch next from tb into @dbname
while @@fetch_status=0
begin
exec('sp_detach_db '''+@dbname+'''')
fetch next from tb into @dbname
end
close tb
deallocate tb