alguien podria ayudarme a saber si existe un registro igual al que se va a insertar hacer una cosa, si no permitir que se inserte.
La base esta Online
Mysql Evitar registro duplicado
Moderator: Neosoft Support
Re: Mysql Evitar registro duplicado
Aqui un ejemplo, solo cambiar los datos:
InputBox "Nuevo Maestro" "Ingrese el nombre del nuevo docente:" "[nuevo]"
dbpFind "estudiantes" "maestros" "Maestro" "[nuevo]" "ExactMatch=Yes;CaseSensitive=No"
If "[dbpError]" ">" ""
.agregar aqui el script para añadir el registro
Else
AlertBox "Error" " El nombre del docente ya existe.|Vuelva a intentar con un nuevo nombre."
GotoLine "end"
EndIf
InputBox "Nuevo Maestro" "Ingrese el nombre del nuevo docente:" "[nuevo]"
dbpFind "estudiantes" "maestros" "Maestro" "[nuevo]" "ExactMatch=Yes;CaseSensitive=No"
If "[dbpError]" ">" ""
.agregar aqui el script para añadir el registro
Else
AlertBox "Error" " El nombre del docente ya existe.|Vuelva a intentar con un nuevo nombre."
GotoLine "end"
EndIf
Re: Mysql Evitar registro duplicado
Gracias por tu ayuda pero lo que necesito es la sintaxis de como debería ser en Mysql
Re: Mysql Evitar registro duplicado
You could create a procedure that returns the count of users with the same fn, ln and dob. Then IF Count > 0 'User (maybe) already exist' Else create account.
TSQL:
[syntax=sql]
CREATE PROCEDURE TeacherExist
@Count INT,
@FirstName VARCHAR(70),
@LastName VARCHAR(35),
@DoB DATE
AS BEGIN
SET @Count =
(SELECT COUNT(*) FROM Teachers
WHERE
Teachers.FirstName = @FirstName AND
Teachers.LastName = @LastName AND
Teachers.DateOfBirth = @DoB);
SELECT @Count;
END
[/syntax]
TSQL:
[syntax=sql]
CREATE PROCEDURE TeacherExist
@Count INT,
@FirstName VARCHAR(70),
@LastName VARCHAR(35),
@DoB DATE
AS BEGIN
SET @Count =
(SELECT COUNT(*) FROM Teachers
WHERE
Teachers.FirstName = @FirstName AND
Teachers.LastName = @LastName AND
Teachers.DateOfBirth = @DoB);
SELECT @Count;
END
[/syntax]