IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_DnDel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[sp_DnDel]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[rds].[sp_DnDel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [rds].[sp_DnDel]
GO

CREATE procedure [RDS].[sp_DnDel] @FileID uniqueidentifier
as
BEGIN 

--удалить пресенсы
delete pres
from [RDS].T_DN_ITEM_PLAN itemplan
join [RDS].T_DN_ITEM dnitem on dnitem.DnItemID = itemplan.DnItem and dnitem.DnFile = @FileID
--удалить dn_item
delete [RDS].T_DN_ITEM
where DnFile = @FileID
--удалить dn_file
delete [RDS].T_DN_FILE
where FileID = @FileID

END