【问题标题】:How insert with no duplicates? [duplicate]如何插入没有重复? [复制]
【发布时间】:2017-07-06 13:53:42
【问题描述】:

我正在尝试在我的产品表中插入一些记录,我需要插入没有重复型号代码的产品,我使用查询:

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?有什么区别? 插入无效,有什么建议吗?提前致谢!

【问题讨论】:

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

标签: mysql


【解决方案1】:

我需要插入没有重复型号代码的产品

那么为什么不在erp_model 列上定义UNIQUE 约束。喜欢

ALTER TABLE erp_product ADD CONSTRAINT constr_unq UNIQUE (erp_model)

【讨论】:

    猜你喜欢
    • 2019-10-20
    • 2018-03-09
    • 1970-01-01
    • 1970-01-01
    • 2011-04-24
    • 2013-01-07
    • 1970-01-01
    • 2017-11-23
    • 1970-01-01
    相关资源
    最近更新 更多