我有下表,希望确保每一行都是唯一的。sku_simple_product、branding_position_de、branding_id、handling_group_id和pre_cost_id的组合必须在此表中只存在一次。
branding_position_id int(255) Auto-Inkrement
sku_simple_product text
branding_position_de text
branding_position_en text NULL
branding_position_fr text NULL
branding_position_es text NULL
branding_position_it text NULL
branding_position_pl text NULL
branding_position_nl text NULL
branding_id varchar(255)
handling_group_id varchar(255) NULL
is_branding_incl int(11) [0]
pre_cost_id varchar(255)现在我有以下问题:
发布于 2019-04-15 14:23:25
创建UNIQUE约束,如下所示:
alter table my_table add constraint uq1 (
sku_simple_product,
branding_position_de,
branding_id,
handling_group_id,
pre_cost_id
);但是,由于列的数据类型为TEXT,此解决方案具有很高的潜在性。TEXT列可以存储非常大的文本片段,检查它们的唯一性可能会很慢。
如果可能的话,我建议将类型更改为较小的类型,如VARCHAR。
发布于 2019-04-15 14:30:23
INSERT INTO companies
(id, full_name, address, phone_number)
VALUES
(1, ‘Apple’, '1 Infinite Loop, Cupertino, California', 18002752273)
ON DUPLICATE KEY UPDATE
full_name = ‘Apple’
address = ‘1 Infinite Loop, Cupertino, California’
phone_number = 18002752273;https://stackoverflow.com/questions/55691209
复制相似问题