USE [EnVisage]
GO

IF not EXISTS (SELECT * FROM sys.tables where name like 'CostSaving')
begin
begin tran
	CREATE TABLE [dbo].[CostSaving](
		[Id] [uniqueidentifier] NOT NULL,
		[ScenarioId] [uniqueidentifier] NOT NULL,
		[Year] [int] NOT NULL,
		[Month] [smallint] NOT NULL,
		[Cost] [decimal](15,4) not null,
		CONSTRAINT [PK_CostSaving] PRIMARY KEY CLUSTERED 
	(
		[Id] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
	) ON [PRIMARY]
	

	ALTER TABLE [dbo].[CostSaving] ADD  CONSTRAINT [DF_CostSaving_Id]  DEFAULT (newid()) FOR [Id]
	

	ALTER TABLE [dbo].[CostSaving]  WITH CHECK ADD  CONSTRAINT [FK_CostSaving_Scenario] FOREIGN KEY([ScenarioId])
	REFERENCES [dbo].[Scenario] ([Id])
	

	ALTER TABLE [dbo].[CostSaving] CHECK CONSTRAINT [FK_CostSaving_Scenario]
	
	ALTER TABLE [dbo].[Scenario] ADD [CostSavings] [decimal](15,4) NULL
	
	ALTER TABLE [dbo].[Scenario] ADD [CostSavingsStartDate] [datetime] NULL
	
	ALTER TABLE [dbo].[Scenario] ADD [CostSavingsEndDate] [datetime] NULL

	ALTER TABLE [dbo].[Scenario] ADD [CostSavingsType] [smallint] NULL
	commit tran
end