create database ${DBNAME}
on
(
	name='${DBNAME}',
	filename='${DBFILENAME}',
	size=10mb,
	filegrowth=10mb
)
log on
(
	name='${LOGDBNAME}',
	filename='${LOGDBFILENAME}',
	size=10mb,
	filegrowth=10mb
)
go

use ${DBNAME}
go

if exists(select 1 from master..sysobjects where name='syslogins')
if not exists(select 1 from master..syslogins where name='${USERNAME}')
exec sp_addlogin '${USERNAME}','${PASSWORD}','${DBNAME}'
go

if exists(select 1 from master..sysobjects where name='sysxlogins')
if not exists(select 1 from master..sysxlogins where name='${USERNAME}')
exec sp_addlogin '${USERNAME}','${PASSWORD}','${DBNAME}'
go

exec sp_adduser '${USERNAME}','${USERNAME}','public'
go

exec sp_addrolemember 'db_owner', '${USERNAME}'
go
