USE [EnVisage]
GO

if exists (select 1 from sys.all_objects where name like 'sp_DeleteScenario')
begin
DROP PROCEDURE [dbo].[sp_DeleteScenario]
end
GO

CREATE PROCEDURE [dbo].[sp_DeleteScenario] (@aScenarioOID uniqueidentifier) AS
	BEGIN
	
		BEGIN TRANSACTION

		delete from History where EntityId = @aScenarioOID
		delete from Note where ParentId = @aScenarioOID
		delete from Rate where ParentId = @aScenarioOID
		delete from ScenarioDetail where ScenarioDetail.ParentID = @aScenarioOID
		delete from Scenario2Group where ScenarioId = @aScenarioOID
		delete from PeopleResourceAllocation where ScenarioId = @aScenarioOID
		delete from Scenario where id = @aScenarioOID

		COMMIT TRANSACTION 

 	END



GO


