3

Why SKU field in product table

(catalog_product_entity.sku - VARCHAR(64)) 

does not have UNIQUE index (just simple INDEX for searching) and uniqueness is provided by PHP code? Postfix "-1" is added to the SKU when I update data for existing products and type duplicate values.

001San
001San-1
001San-1-1

OK, naming rule does not work good but why does the table structure contain simple INDEX instead of UNIQUE INDEX?

CREATE TABLE catalog_product_entity (
  entity_id int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Entity ID',
  ...
  sku varchar(64) NOT NULL COMMENT 'SKU',
  ...
  PRIMARY KEY (entity_id),
  ...
  UNIQUE INDEX CATALOG_PRODUCT_ENTITY_SKU (sku),
  ...
)
  • Agreed, it would allow for ON DUPLICATE KEY UPDATE constructs on low level database inserts. These are safer than two separate queries where one checks the existence of an sku and another for in the insert. – Patrick van Bergen Oct 11 '17 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.