L
L
Lexxtor2014-09-09 00:10:57
MySQL
Lexxtor, 2014-09-09 00:10:57

What is the best way to make a MySQL table of products, only with a primary barcode, or with an ID for products without a barcode?

I am making a modern analogue of goodsmatrix.ru and habrahabr.ru/post/78826
I want to store goods with and without a barcode.
Barcodes are stored in a table with the Unsigned BIGINT field (it allows values ​​from 0 to 18446744073709551615):

CREATE TABLE IF NOT EXISTS `goods_item` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `gtin` bigint(16) unsigned DEFAULT NULL, -- штрихкод
  `category_id` int(10) unsigned DEFAULT NULL,
  `name` varchar(120) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `gtin_UNIQUE` (`gtin`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

Usually a barcode consists of 13 digits and cannot start with 2.
And the idea came up to remove the ID, and make the GTIN primary and set AUTO_INCREMENT to 20000000000, there will be room for 9 billion keys for goods without a barcode and the field for identifying all goods will be one. That is, if the barcode is not specified, then the AUTO_INCREMENT value is written to it.
Is this a good idea or are there any problems?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Philip, 2014-09-09
@shcherbanich

AUTO_INCREMENT will go from the maximum value until everything is packed to capacity, maybe a real gtin will be generated, and a problem will arise.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question