-1

I'm trying to insert some records in my product table, I need to insert products where are no repeating model code, I use the query:

INSERT IGNORE INTO erp_product
  (erp_model, erp_ean, erp_cstid, erp_quantity,
  erp_brand_erp_brandid, erp_price, erp_cost, 
  erp_weight, erp_lenght, erp_width, erp_height,
  erp_status, erp_distributor, erp_registerdate)
VALUES(
       '020-113_24','7897712061589',1,0,
       '1','22.85','17.58',
       '0.03','13','14','5',
       0,'OP','06/07/2017 10:32:47');

I need use WHERE NOT IN or WHERE NOT EXISTS? What is the difference? The insert not works, any suggestion? Thanks in advance!

Michael
  • 5,095
  • 2
  • 13
  • 35
Vinícius
  • 443
  • 1
  • 8
  • 29

1 Answers1

1

I need to insert products where are no repeating model code

Well then why not define a UNIQUE constraint on erp_model column. like

ALTER TABLE erp_product ADD CONSTRAINT constr_unq UNIQUE (erp_model)
Rahul
  • 76,197
  • 13
  • 71
  • 125