-- This file is part of the it-crafts software and is subject to copyright protection.
-- (C) 2022, All rights reserved by Steffen Anders, Elsteraue - Germany
-- Visit also https://www.it-crafts.de.
--

-- --------------------------------------------------------------------- Loeschtrigger
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'TR'   and [name] = 'tr_OCVendor_OnDelete')
  DROP TRIGGER [dbo].[tr_OCVendor_OnDelete]
GO
CREATE TRIGGER tr_OCVendor_OnDelete ON ut_OCVendor FOR DELETE
AS
  IF @@NESTLEVEL < 10
  BEGIN
    DELETE FROM [dbo].[ut_OCVendorFile] WHERE RecId IN
    (SELECT X.RecId FROM [dbo].[ut_OCVendorFile] X INNER JOIN DELETED D ON X.[VendorId] = D.[Ident])
  END
GO

--- ------------------------------------------------------------ Alle Open-Connect-Lieferanten loeschen
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'itcproc_OCVendor_DeleteAll')
  DROP PROCEDURE [dbo].[itcproc_OCVendor_DeleteAll]
GO
CREATE PROCEDURE [dbo].[itcproc_OCVendor_DeleteAll]
AS
  DELETE FROM [dbo].[ut_OCVendor]
  SELECT 1 AS success
GO
