PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > How to check in a stored proc if data is already present?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How to check in a stored proc if data is already present?

Réponse
 
LinkBack Outils de la discussion
Vieux 23/12/2007, 21h04   #1
Bruno Panetta
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to check in a stored proc if data is already present?

I have a stored proc like the following. It works on a table called
ProductType with only one field, called ProductTypeName.

DROP PROCEDURE IF EXISTS myDB.setProductType;
CREATE PROCEDURE myDB.`setProductType`(

IN ProductType VARCHAR(20))
BEGIN
INSERT INTO ProductType
(
ProductTypeName
)
VALUES
(
ProductTypeName );
END;

It works fine, but I would like to avoid duplicates. How can I make
the stored proc check if that ProductTypeName is already in the table,
and only insert it if it's not? Thanks.
  Réponse avec citation
Vieux 23/12/2007, 21h31   #2
Ana C. Dent
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to check in a stored proc if data is already present?

Bruno Panetta <bpanetta@gmail.com> wrote in news:9ffbff93-5518-414e-a8dd-
5f8f3a8b3298@b40g2000prf.googlegroups.com:

> I have a stored proc like the following. It works on a table called
> ProductType with only one field, called ProductTypeName.
>
> DROP PROCEDURE IF EXISTS myDB.setProductType;
> CREATE PROCEDURE myDB.`setProductType`(
>
> IN ProductType VARCHAR(20))
> BEGIN
> INSERT INTO ProductType
> (
> ProductTypeName
> )
> VALUES
> (
> ProductTypeName );
> END;
>
> It works fine, but I would like to avoid duplicates. How can I make
> the stored proc check if that ProductTypeName is already in the table,
> and only insert it if it's not? Thanks.
>


Place a UNIQUE index on that column which will preclude duplicates.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h05.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,07815 seconds with 10 queries