2017-07-06 53 views
-1

我想插入我的产品表中的一些记录,我需要插入其中没有重复的模型代码的产品,我用的是查询:如何插入不重复?

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'); 

我需要使用WHERE NOT INWHERE NOT EXISTS?有什么不同? 插入不起作用,有什么建议?提前致谢!

+0

表上存在哪些主键/唯一键? –

回答

1

我需要插入其中没有重复的模型代码

那好产品为什么不上erp_model列中定义的UNIQUE约束。像

ALTER TABLE erp_product ADD CONSTRAINT constr_unq UNIQUE (erp_model)