Update:
We ended up extending the answer from Baaju, so I decided to share it. We call the following script from MSBuild and clear all existing databases created during testing:
use master
DECLARE @Name nvarchar(1000);
DECLARE testdb_cursor CURSOR FOR
SELECT 'ALTER DATABASE' + '[' + NAME + ']' + ' SET SINGLE_USER WITH ROLLBACK IMMEDIATE DROP DATABASE ' + '[' + NAME + ']' FROM sys.sysdatabases where name like 'TCM.%'
OPEN testdb_cursor;
FETCH NEXT FROM testdb_cursor
INTO @Name;
WHILE @@FETCH_STATUS = 0
BEGIN
exec sp_executesql @Name;
FETCH NEXT FROM testdb_cursor
INTO @Name;
END
CLOSE testdb_cursor;
DEALLOCATE testdb_cursor;
abarr source
share