USE [EnVisage]
GO

if exists (select * from sys.all_objects where name like 'FK_Expenditure2Expenditure_ExpenditureCategory' and parent_object_id = OBJECT_ID('Expenditure2Expenditure') and type = 'F ')
begin
ALTER TABLE Expenditure2Expenditure DROP CONSTRAINT FK_Expenditure2Expenditure_ExpenditureCategory
end

ALTER TABLE [dbo].[Expenditure2Expenditure]  WITH CHECK ADD  CONSTRAINT [FK_Parent_ExpenditureCategory] FOREIGN KEY([ParentId])
REFERENCES [dbo].[Expenditure_Category] ([Id])
GO

ALTER TABLE [dbo].[Expenditure2Expenditure] CHECK CONSTRAINT [FK_Parent_ExpenditureCategory]
GO

ALTER TABLE [dbo].[Expenditure2Expenditure]  WITH CHECK ADD  CONSTRAINT [FK_Child_ExpenditureCategory] FOREIGN KEY([ChildId])
REFERENCES [dbo].[Expenditure_Category] ([Id])
GO

ALTER TABLE [dbo].[Expenditure2Expenditure] CHECK CONSTRAINT [FK_Child_ExpenditureCategory]
GO

