MySQL Forums
Forum List  »  Spanish

Estructura en trigger
Posted by: Ruben Urquijo
Date: July 28, 2008 05:20AM

Hola, me veo en la necesidad de utilizar una estructura if..then en un trigger, pero no se como utilizar dicha estructura.

El trigger que ejecuto es el siguiente:
DELIMITER $$

DROP TRIGGER `sist_final`.`audit_in_paciente`$$

create trigger `audit_in_paciente` AFTER INSERT on `paciente`
for each row BEGIN
DECLARE login varchar(50);
declare hora time;
declare fecha date;
set hora = current_time();
set fecha = current_date();
select nombre_usuario into login from usuario where estado = 'Activo';
insert into auditoria (usuario,fecha,hora,accion,modulo) values (login,fecha,hora,'Inserción','Gestión Pacientes');
end$$

DELIMITER ;

La pregunta surge de 2 maneras:
- Cuando el "select nombre_usuario...." no devuelve nada quiere decir que entro el usuario Admin, que lo tengo establecido en el sistema como maestro (en este caso quiero colocar el if..then para establecer la variable login como 'Admin')
- Que sucede cuando el resultado del select me devuelve mas de un usuario, ya que posiblemente el sistema se utilice como cliente-servidor; como saber cual es el usuario que realizo la operación?

Espero que puedan ayudarme y entendido lo que necesito.

Saludos y gracias.

Options: ReplyQuote


Subject
Views
Written By
Posted
Estructura en trigger
5281
July 28, 2008 05:20AM
1928
August 13, 2008 09:02PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.