-- dbo.ET_TabVyrCisPrikaz_HDC_D
CREATE TRIGGER dbo.ET_TabVyrCisPrikaz_HDC_D ON dbo.TabVyrCisPrikaz
WITH EXECUTE AS CALLER
FOR DELETE
AS
BEGIN
 SET NOCOUNT ON
 
 DECLARE
  @id INT,
  @idVPr INT,
  @vyrCis NVARCHAR(100),
  @popis NVARCHAR(100)


 DECLARE c CURSOR LOCAL FAST_FORWARD FOR
  SELECT d.ID, d.IDPrikaz, d.VyrCislo, d.Popis
   FROM deleted d
 OPEN c
 WHILE (1=1)
  BEGIN
   FETCH NEXT FROM c INTO @id, @idVPr, @vyrCis, @popis
   IF (@@FETCH_STATUS<>0) BREAK

-- begin: reseni HDC/DZ API
   IF OBJECT_ID(N'dbo._TabVyroba_Palety', N'U') IS NOT NULL
    DELETE FROM dbo._TabVyroba_Palety WHERE IDPrikaz=@idVPr AND CisloPalety=@vyrCis AND Sarze=@popis
-- end: reseni HDC/DZ API

  END
 CLOSE c
 DEALLOCATE c



-- cisteni seedu
 IF EXISTS(SELECT 1 FROM dbo.TabVyrCisPrikaz)
  BEGIN
   SELECT @id=ISNULL(MAX(ID),1) FROM dbo.TabVyrCisPrikaz
   DBCC CHECKIDENT (TabVyrCisPrikaz, RESEED, @id)
  END

END
