MySQL - Ayuda trigger

 
Vista:

Ayuda trigger

Publicado por Luis (1 intervención) el 14/02/2008 22:39:35
Me sale un error al ejecutar el trigger

CREATE TABLE `documento` (
`IdDocumento` decimal(9,0) NOT NULL,
`IdRadicado` decimal(7,0) NOT NULL,
`Fecha` date NOT NULL,
`Ciudad` varchar(18) NOT NULL,
`Asunto` varchar(50) NOT NULL,
PRIMARY KEY (`IdDocumento`)
) ;
CREATE TRIGGER consecutivo_doc
BEFORE
INSERT ON Documento
FOR EACH ROW
BEGIN
DECLARE maxrad INT;
SELECT INTO SET maxrad = MAX(idRadicado) FROM Documento
WHERE idTipoDocumento=NEW.idTipoDocumento and YEAR(fecha)=YEAR(NEW.fecha);
IF maxrad!=null THEN NEW.idRadicado=@maxrad+1;
ELSE NEW.idRadicado=1;
END IF;
END;

ERROR 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INT' at line 6
ERROR 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTO SET maxrad = MAX(idRadicado) FROM Documento
WHERE idTipoDocumento=NEW.idTi' at line 1
ERROR 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF maxrad!=null THEN NEW.idRadicado=@maxrad+1' at line 1
ERROR 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ELSE NEW.idRadicado=1' at line 1
ERROR 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END IF' at line 1
ERROR 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END' at line 1
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Ayuda trigger

Publicado por fredusca (1 intervención) el 27/03/2009 03:16:50
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<?php

// Primero comprobamos que ningún campo esté vacío.
if(isset' at line 1

<?php

// Primero comprobamos que ningún campo esté vacío.
if(isset($_POST['usuario']) && !empty($_POST['usuario']) &&
isset ($_POST['nombre']) && !empty($_POST['nombre']) &&
isset($_POST['apellidos']) && !empty($_POST['apellidos']) &&
isset($_POST['email']) && !empty($_POST['email']) &&
isset($_POST['password']) && !empty($_POST['telefono']) &&
isset($_POST['telefono']) && !empty($_POST['email'])) {

// Si entramos es que todo se ha realizado correctamente

$link = mysql_connect("localhost","root","sila21");
mysql_select_db("registro",$link);

// Con esta sentencia SQL insertaremos los datos en la base de datos
mysql_query("INSERT INTO usuarios (usuario,,nombre,apellidos,email,password,telefono)
VALUES ('{$_POST['usuario']}','{$_POST['nombre']}','{$_POST['apellidos']}','{$_POST['email']}','{$_POST['password']}','{$_POST['telefono']}')",$link);

// Ahora comprobaremos que todo ha ido correctamente
$my_error = mysql_error($link);

if(!empty($my_error)) {

echo "Ha habido un error al insertar los valores. $my_error";

} else {

echo "Los datos han sido introducidos satisfactoriamente";

}

} else {

echo "Error, no ha introducido todos los datos";

}

?>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar