if (select top 1 0 from sys.databases where name = 'NucelarMonitor') is null create database NucelarMonitor collate Latin1_General_100_CI_AS_SC_UTF8
go
use NucelarMonitor

if object_id(N'dbo.ProceduresView', N'V') is not null drop view dbo.ProceduresView
go
create view dbo.ProceduresView as select 
    procedures.id, 
    databases.[name] as [database], 
    procedures.[name] as [procedure], 
    procedures.date_in, 
    procedures.date_out
from dbo.Procedures procedures
join dbo.Databases databases on databases.id = procedures.[database]
where 
    procedures.date_out is null and 
    databases.date_out is null
go

if object_id(N'dbo.ExceptionsView', N'V') is not null drop view dbo.ExceptionsView
go
create view dbo.ExceptionsView as select 
    exceptions.id, 
    procedures.[database] as [database], 
    procedures.[procedure] as [procedure], 
    messages.[key] as [message], 
    parameters.[value] as [parameters], 
    exception.[value] as [exception], 
    exceptions.[status], 
    exceptions.code, 
    exceptions.date_in
from dbo.Exceptions exceptions
join dbo.ProceduresView procedures on procedures.id = exceptions.[procedure]
join dbo.Messages messages on messages.id = exceptions.[message]
join dbo.BigData parameters on parameters.id = exceptions.parameters
join dbo.BigData exception on exception.id = exceptions.exception
where 
    exceptions.date_out is null and 
    procedures.date_out is null and 
    messages.date_out is null and 
    parameters.date_out is null and 
    exception.date_out is null
go