CreateDatabase.sql 1.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/*
	--Creates PerformanceCollector db if it does not exist, and only if it was requested.  The .ps1 deploy script determines if this should be called.    
	--Makes no attempt to install the db files on anything but the default file locations.  YOU SHOULD ALTER THIS.    
	--You can always build the PerformanceCollector db yourself, in which case this script does nothing.  Then you can customize it to suit your needs and
		standards.  

*/
SET NOCOUNT ON 

IF NOT EXISTS (SELECT 1 FROM master..sysdatabases WHERE NAME = 'PerformanceCollector')
BEGIN
	PRINT 'Database is not found.  Database will be created.'
	
	DECLARE @SQL VARCHAR(MAX);	
	
	-------------------------------------------------------------
	-- Build and execute the Create Database command
	-------------------------------------------------------------
	PRINT 'Executing the Create Database command...'
	SELECT @SQL = '
	CREATE DATABASE PerformanceCollector'
	PRINT @SQL 
	BEGIN TRY
		EXEC(@SQL)
		EXEC ('ALTER DATABASE PerformanceCollector SET RECOVERY SIMPLE');
	END TRY
	BEGIN CATCH
		PRINT ERROR_MESSAGE()
		PRINT ERROR_NUMBER()
		PRINT 'The above error occurred while trying to CREATE DATABASE. '
		RAISERROR ('See previous errors',16,1) 
	END CATCH
	
END
GO
USE PerformanceCollector
GO
EXEC sp_changedbowner 'sa'
GO