-- dbo.ET_TabVyroba_PaletyUkonceni_D
CREATE TRIGGER dbo.ET_TabVyroba_PaletyUkonceni_D ON dbo._TabVyroba_PaletyUkonceni
WITH EXECUTE AS CALLER
FOR DELETE
AS
BEGIN
 SET NOCOUNT ON

-- !! trigger neupravujte, bude stejne pregenerovan pri startu pluginu PluginHDCRTN !!

 DECLARE
  @id INT
  
 DECLARE c CURSOR LOCAL FOR
  SELECT d.ID
   FROM deleted d
 OPEN c
 WHILE (1=1)
  BEGIN
   FETCH NEXT FROM c INTO @id
   IF (@@FETCH_STATUS<>0) BREAK
  END
 CLOSE c
 DEALLOCATE c  



-- cisteni 
 IF EXISTS(SELECT 1 FROM dbo._TabVyroba_PaletyUkonceni)
   BEGIN
    SELECT @id=MAX(ID) FROM dbo._TabVyroba_PaletyUkonceni
    DBCC CHECKIDENT(_TabVyroba_PaletyUkonceni, RESEED, @id)
   END
  ELSE
   TRUNCATE TABLE dbo._TabVyroba_PaletyUkonceni

END