USE [envisage]
GO

/****** Object:  StoredProcedure [dbo].[sp_DeleteScenario]    Script Date: 28.08.2014 14:21:24 ******/
if exists (select * from sys.all_objects where name like 'sp_DeleteScenario')
DROP PROCEDURE [dbo].[sp_DeleteScenario]
GO

/****** Object:  StoredProcedure [dbo].[sp_DeleteScenario]    Script Date: 28.08.2014 14:21:24 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
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 Scenario_Detail where Scenario_Detail.ParentID = @aScenarioOID
		delete from Scenario_Snapshot where ParentID = @aScenarioOID
		delete from Scenario_Wide where ScenarioId = @aScenarioOID
		delete from ScenarioAccess where ScenarioAccess.ParentId = @aScenarioOID
		delete from Scenario where id = @aScenarioOID

		COMMIT TRANSACTION 

 	END

GO


