lucasarts_18
06-09-2005, 00:44:07
Hola:
Alguién sabe como puede saber el trigger que datos fueron actualizados..
Saludos.:p
__hector
06-09-2005, 19:38:57
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.
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.
lucasarts_18
06-09-2005, 23:16:18
Hola:
hector, gracias de nuevo por ayudarme y, efectivamente es lo que necesito, averiguaré más sobre estas funciones..
Muchas Gracias..;)
vBulletin v3.6.8, Derechos ©2000-2024, Jelsoft Enterprises Ltd.