USE [EnVisage]
GO

if exists(select 1 from sys.all_objects where name='PeopleResourceAllocation')
	DROP TABLE [dbo].[PeopleResourceAllocation]


CREATE TABLE [dbo].[PeopleResourceAllocation](
	[Id] [uniqueidentifier] NOT NULL,
	[ScenarioId] [uniqueidentifier] NOT NULL,
	[ResourceID] [uniqueidentifier] NOT NULL,
	[ExpenditureCategoryId] [uniqueidentifier] NOT NULL,
	[WeekEndingDate] [datetime] NULL,
	[Quantity] [decimal](18, 6) NULL,
	[LastUpdate] [datetime] NULL,
	[WeekOrdinal] [int] NULL,
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[PeopleResourceAllocation] ADD  CONSTRAINT [DF_PeopleResourceAllocation_Id]  DEFAULT (newid()) FOR [Id]
GO

ALTER TABLE dbo.[PeopleResourceAllocation] ADD CONSTRAINT
	PK_PeopleResourceAllocation PRIMARY KEY CLUSTERED 
	(
	Id
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO

ALTER TABLE [dbo].[PeopleResourceAllocation]  WITH CHECK ADD  CONSTRAINT [FK_PeopleResourceAllocation_ExpenditureCategory] FOREIGN KEY([ExpenditureCategoryId])
REFERENCES [dbo].[Expenditure_Category] ([Id])
GO

ALTER TABLE [dbo].[PeopleResourceAllocation] CHECK CONSTRAINT [FK_PeopleResourceAllocation_ExpenditureCategory]
GO

ALTER TABLE [dbo].[PeopleResourceAllocation]  WITH CHECK ADD  CONSTRAINT [FK_PeopleResourceAllocation_Scenario] FOREIGN KEY([ScenarioId])
REFERENCES [dbo].[Scenario] ([Id])
GO

ALTER TABLE [dbo].[PeopleResourceAllocation] CHECK CONSTRAINT [FK_PeopleResourceAllocation_Scenario]
GO

ALTER TABLE [dbo].[PeopleResourceAllocation]  WITH CHECK ADD  CONSTRAINT [FK_PeopleResourceAllocation_PeopleResource] FOREIGN KEY([ResourceId])
REFERENCES [dbo].[PeopleResource] ([Id])
GO

ALTER TABLE [dbo].[PeopleResourceAllocation] CHECK CONSTRAINT [FK_PeopleResourceAllocation_PeopleResource]
GO