|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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. |
|
![]() |
| Outils de la discussion | |
|
|