
if not exists(select s.schema_id from sys.schemas s where s.name = 'optima') 
	and exists(select p.principal_id from sys.database_principals p where p.name = 'dbo') begin
	exec sp_executesql N'create schema [optima] authorization [dbo]'
end

if not exists(select s.schema_id from sys.schemas s where s.name = 'dwh') 
	and exists(select p.principal_id from sys.database_principals p where p.name = 'dbo') begin
	exec sp_executesql N'create schema [dwh] authorization [dbo]'
end

if not exists(select s.schema_id from sys.schemas s where s.name = 'autoline') 
	and exists(select p.principal_id from sys.database_principals p where p.name = 'dbo') begin
	exec sp_executesql N'create schema [autoline] authorization [dbo]'
end

if not exists(select s.schema_id from sys.schemas s where s.name = 'autosys') 
	and exists(select p.principal_id from sys.database_principals p where p.name = 'dbo') begin
	exec sp_executesql N'create schema [autosys] authorization [dbo]'
end

if not exists(select s.schema_id from sys.schemas s where s.name = 'audev') 
	and exists(select p.principal_id from sys.database_principals p where p.name = 'dbo') begin
	exec sp_executesql N'create schema [audev] authorization [dbo]'
end

if not exists(select s.schema_id from sys.schemas s where s.name = 'ari') 
	and exists(select p.principal_id from sys.database_principals p where p.name = 'dbo') begin
	exec sp_executesql N'create schema [ari] authorization [dbo]'
end

if not exists(select s.schema_id from sys.schemas s where s.name = 'datev') 
	and exists(select p.principal_id from sys.database_principals p where p.name = 'dbo') begin
	exec sp_executesql N'create schema [datev] authorization [dbo]'
end

if not exists(select s.schema_id from sys.schemas s where s.name = 'carlo') 
	and exists(select p.principal_id from sys.database_principals p where p.name = 'dbo') begin
	exec sp_executesql N'create schema [carlo] authorization [dbo]'
end

if not exists(select s.schema_id from sys.schemas s where s.name = 'locosoft') 
	and exists(select p.principal_id from sys.database_principals p where p.name = 'dbo') begin
	exec sp_executesql N'create schema [locosoft] authorization [dbo]'
end

if not exists(select s.schema_id from sys.schemas s where s.name = 'werwiso') 
	and exists(select p.principal_id from sys.database_principals p where p.name = 'dbo') begin
	exec sp_executesql N'create schema [werwiso] authorization [dbo]'
end

if not exists(select s.schema_id from sys.schemas s where s.name = 'aa_dwh') 
	and exists(select p.principal_id from sys.database_principals p where p.name = 'dbo') begin
	exec sp_executesql N'create schema [aa_dwh] authorization [dbo]'
end

if not exists(select s.schema_id from sys.schemas s where s.name = '1_dwh') 
	and exists(select p.principal_id from sys.database_principals p where p.name = 'dbo') begin
	exec sp_executesql N'create schema [1_dwh] authorization [dbo]'
end

if not exists(select s.schema_id from sys.schemas s where s.name = 'hs') 
	and exists(select p.principal_id from sys.database_principals p where p.name = 'dbo') begin
	exec sp_executesql N'create schema [hs] authorization [dbo]'
end

if not exists(select s.schema_id from sys.schemas s where s.name = 'p2') 
	and exists(select p.principal_id from sys.database_principals p where p.name = 'dbo') begin
	exec sp_executesql N'create schema [p2] authorization [dbo]'
end
GO

