create proc sp_CreateDatabase
/*--声明变量--*/
@databasename varchar(256),
@user varchar(64),
@pwd varchar(128),
@path varchar(256) ='d:\data' 

as
declare @sql varchar(max)
set @sql='
create DATABASE '+@databasename+'
ON PRIMARY
(
	name='+@databasename+',
	filename= '''+@path+'\'+@databasename+'.mdf'',
	size=5mb,
	filegrowth=15%
)
log on
(
	name='+@databasename+'_log,
	filename='''+@path+'\'+@databasename+'_log.ldf'',
	size=5mb
)

ALTER DATABASE '+@databasename+' set recovery Simple ;'
exec (@sql)

set @sql='
if not exists (select * from sys.sql_logins where name='''+@user+''')
/*-- 创建SQL用户 --*/
create login '+@user+' with password='''+@pwd+''', default_database='+@databasename+'
/*-- 在指定数据库添加用户 --*/
use '+@databasename+'
create user '+@user+' for login '+@user+' with default_schema=dbo
exec sp_addrolemember ''db_owner'','+@user+'
'

print @sql
exec (@sql)