Ver Mensaje Individual
  #2  
Antiguo 06-09-2005
Avatar de __hector
[__hector] __hector is offline
Miembro Premium
 
Registrado: may 2003
Ubicación: Santo Domingo, Rep. Dom.
Posts: 1.075
Reputación: 25
__hector Va por buen camino
ah???

Si te refieres a saber si un campo fue actualizado, utiliza la funcion UPDATE y COLUMNS_UPDATED, que te permite saber si una columna sufrio cambios en la actualizacion de la tabla.

Código:
CREATE TRIGGER updEmployeeData 
ON employeeData 
FOR update AS
/*Check whether columns 2, 3 or 4 has been updated. If any or all of columns 
2, 3 or 4 have been changed, create an audit record. The bitmask is: 
power(2,(2-1))+power(2,(3-1))+power(2,(4-1)) = 14. To check if all columns 
2, 3, and 4 are updated, use = 14 in place of >0 (below).*/

   IF (COLUMNS_UPDATED() & 14) > 0
/*Use IF (COLUMNS_UPDATED() & 14) = 14 to see if all of columns 2, 3, and 4 are updated.*/
      BEGIN
-- Audit OLD record.
      INSERT INTO auditEmployeeData
         (audit_log_type,
         audit_emp_id,
         audit_emp_bankAccountNumber,
         audit_emp_salary,
         audit_emp_SSN)
         SELECT 'OLD', 
            del.emp_id,
            del.emp_bankAccountNumber,
            del.emp_salary,
            del.emp_SSN
         FROM deleted del

-- Audit NEW record.
      INSERT INTO auditEmployeeData
         (audit_log_type,
         audit_emp_id,
         audit_emp_bankAccountNumber,
         audit_emp_salary,
         audit_emp_SSN)
         SELECT 'NEW',
            ins.emp_id,
            ins.emp_bankAccountNumber,
            ins.emp_salary,
            ins.emp_SSN
         FROM inserted ins
   END
GO
Si quieres ver ejemplos y casos de uso, mira la ayuda en los books online o google.
__________________
Héctor Geraldino
Software Engineer
Responder Con Cita