SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[adminAddDatabase]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[adminAddDatabase]
GO


create procedure dbo.adminAddDatabase
	@pDatabaseName varchar(50)
as
/*************************************************************************
Add the specified database to the SQL Server metadatabase.
Note that this procedure does not create the database working 
folders in the file system or SourceSafe sub-projects. 
**************************************************************************/
declare @err int,
	@procedureName varchar(100)

set @procedureName = db_name() + '.' 
		+ user_name(objectproperty(@@procid,'OwnerId')) 
		+ '.' + object_name(@@procid)

insert Admin.dbo.SqlDatabase 
		(databaseName)
select @pDatabaseName

set @err = @@error
if @err <> 0
	goto ErrorHandler

-- audit 
insert Admin.dbo.ActivityLog (activity)
select @procedureName + ' ' + @pDatabaseName + ' complete successfully'

return

ErrorHandler:
insert Admin.dbo.ActivityLog (activity)
select @procedureName + ' ' + @pDatabaseName 
	+ ' failed with err: ' + cast(@err as varchar(11)) 
raiserror(59001,16,1,@procedureName)

return -1


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

