EnVisageOnline/Main/Database/Schema/Stored Procedures/dbo.sp_DeleteProject.sql

35 lines
3.2 KiB
Transact-SQL
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
Run this script on SQL Server 2008 or later. There may be flaws if running on earlier versions of SQL Server.
*/
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_DeleteProject]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[sp_DeleteProject]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[sp_DeleteProject] (@id uniqueidentifier) AS
BEGIN
BEGIN TRANSACTION
select Id into #scenarioId2Delete from Scenario where Scenario.ParentId = @id
delete from dbo.TeamAllocation where ScenarioId in (select id from #scenarioId2Delete)
delete from dbo.Team2Scenario where ScenarioId in (select id from #scenarioId2Delete)
delete from dbo.CostSaving where ScenarioId in (select id from #scenarioId2Delete)
delete from dbo.PeopleResourceAllocation where ScenarioId in (select id from #scenarioId2Delete)
delete from History where EntityId in (select id from #scenarioId2Delete)
delete from Note where ParentId in (select id from #scenarioId2Delete)
delete from Rate where ParentId in (select id from #scenarioId2Delete)
delete from ScenarioDetail where ScenarioDetail.ParentID in (select id from #scenarioId2Delete)
delete from Scenario_Snapshot where ParentID in (select id from #scenarioId2Delete)
delete from Scenario_Wide where ScenarioId in (select id from #scenarioId2Delete)
delete from ScenarioAccess where ScenarioAccess.ParentId in (select id from #scenarioId2Delete)
delete from Scenario where id in (select id from #scenarioId2Delete)
delete from Project where id = @id
COMMIT TRANSACTION
END
GO