IF EXISTS(SELECT * FROM sysobjects O, sysusers U
          WHERE
            o.name = 'DTULTATU_TIPOSUPRI'  and
            type = 'TR'               and
            u.uid = o.uid             and
            u.name = USER)
   DROP TRIGGER DTULTATU_TIPOSUPRI
GO

CREATE TRIGGER DTULTATU_TIPOSUPRI
ON TIPOSUPRI
FOR INSERT, UPDATE, DELETE
AS
BEGIN
   IF (0 = (SELECT COUNT(*) FROM INSERTED)) BEGIN
      INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
			      (SELECT 'TIPOSUPRI', null, 'CDTIPOSUPRI='+ CDTIPOSUPRI+ ';', GETDATE() FROM DELETED)
   END
   ELSE BEGIN
      UPDATE TIPOSUPRI
      SET DTULTATUTPSUPRI = GETDATE()
      FROM INSERTED
      WHERE (ISNULL(TIPOSUPRI.CDTIPOSUPRI,0) = ISNULL(INSERTED.CDTIPOSUPRI,0)) AND
            (ISNULL(TIPOSUPRI.NMTIPOSUPRI,0) = ISNULL(INSERTED.NMTIPOSUPRI,0)) AND
            (ISNULL(TIPOSUPRI.IDTIPOSUPRI,0) = ISNULL(INSERTED.IDTIPOSUPRI,0)) AND
            (ISNULL(TIPOSUPRI.IDACERTOSUPRI,0) = ISNULL(INSERTED.IDACERTOSUPRI,0)) AND
            (ISNULL(TIPOSUPRI.CDTIPOOPER,0) = ISNULL(INSERTED.CDTIPOOPER,0)) ;
   END;
END;
GO  

-- VERSAO --
EXEC ATUVEROBJ 'DTULTATU_TIPOSUPRI','5.11.000';
GO
