On my current project we are using Visual Studio Team System for Database Professionals aka Datadude to manage the deployment of SQL Server objects to our various dev, test, QA and production environments. In doing that I came across a bit of a problem that can easily occur if you are not dliligently testing your deployment scenarios.
A datadude deployment will try and create the database if it doesn't already exist. In order for this to work you need to ensure that the account that you are deploying with has DBCreator permissions on the target server. If it doesn't then ideally you would like the process to end gracefully - unfortunately that doesn't happen. The attempt to create the database will fail and the deployment process will then attempt to create all of the schema objects in master database. If for some reason the account has db_owner permissions in master then all the objects will get created there. This is obviously very bad and if you're not being vigilant then you might not even know that its happened (who ever takes a look in master, right?).
I reported this problem here: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1399149&SiteID=1&mode=1 and Jamie Laflen from the Datadude dev team told me that this problem has been fixed in SP1 which is due soon. In the meantime, you can apply a simple fix yourself. Put the following code into a pre-build script:
:on error exit
IF NOT EXISTS (SELECT 1 FROM [sys].[databases] WHERE [name] = N'$(DatabaseName)')
BEGIN
RAISERROR(N'The target database, %s, is not available', 16, 127,N'$(DatabaseName)') WITH NOWAIT
RETURN
END
USE [$(DatabaseName)]
GO
:on error resume
Be aware of this. Its potentially quite dangerous.
-Jamie
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1399149&SiteID=1&mode=1