MySQL Forums
Forum List  »  Spanish

Ayuda con procedimiento almacenado
Posted by: Jesús Eduardo Méndez Hilario
Date: May 29, 2016 12:54PM

Tengo la siguiente tabla productos

create database ejemplo;
use ejemplo;

create table producto(
idProducto int not null,
nombre varchar (30),
precio int not null,
PRIMARY KEY(idProducto)
)engine=InnoDB;
Ahora bien, tengo que crear un trigger que solo me permita insertar 3 productos como máximo, hasta ahorita llevo esto:

delimiter //
create trigger producto_in
before insert on producto
for each row
begin
DECLARE errno SMALLINT unsigned DEFAULT 31001;
SET @errmsg = "No se puede ingresar mas de 3 productos";

SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO = errno, MESSAGE_TEXT = @errmsg;
end if;
end//
delimiter ;


Pero no se que sintaxis usar para hacer la condición de que solo se permita máximo 3 registros, ¿alguien me podría ayudar?

Options: ReplyQuote


Subject
Views
Written By
Posted
Ayuda con procedimiento almacenado
1628
May 29, 2016 12:54PM


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.