USE [envisage]

delete ScenarioCln where not exists (select 1 from Scenario where ScenarioCln.Id =Scenario.Id )
GO

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

ALTER TABLE [dbo].[ScenarioCln]  WITH CHECK ADD  CONSTRAINT [FK_ScenarioCln_Scenario] FOREIGN KEY([Id])
REFERENCES [dbo].[Scenario] ([Id])
GO

ALTER TABLE [dbo].[ScenarioCln] CHECK CONSTRAINT [FK_ScenarioCln_Scenario]
GO


