0

I am working on a E-commerce website using Angular, Spring Boot, MySQL. I am implementing a features to allow user to add a product for sale. When user add a product how do you auto generate SKU in MySQL Or is there any other way to make SKU?

This how the product are stored in database:

enter image description here

enter image description here

I am ok with new suggestion with how to make SKU:

I have 8 product category in database:

enter image description here

User only choose Product Category.

coder_sam97
  • 21
  • 1
  • 9
  • Your question is confusing, what is the issue with current approach and what you mean by auto generated? How the auto generated one will differ from the current one? – code_mechanic Apr 07 '21 at 15:10
  • *is there any other way to make SKU?* Use UUID(). – Akina Apr 07 '21 at 15:32
  • @code_mechanic Currently all those products in database are inserted by me and those SKU are hardcoded. But in production I want SKU to be auto generated when a product is added by users into database. user only choose a product category. So If the category is Book then SKU will be BOOK-TECH-auto generated unique number like 1011. if the category is Bag then SKU will be BAG-auto generated unique number like 3033. – coder_sam97 Apr 07 '21 at 15:49
  • @Akina Yes that seems like a good solution. I just wanna know different solution to this problem. thank you – coder_sam97 Apr 07 '21 at 15:54
  • If you could use the `UUID` that's the best approach you can have but if you have to generate as per the logic you mentioned, then every solution will have pros and cons. – code_mechanic Apr 07 '21 at 16:05
  • I personally wanted something like BOOK-TECH-(1000+primary key) So, basically a mysql function will take category as input then concatenate "BOOK-TECH-" + 1000+ "product primary key" then if product primary key 20 then SKU will be "BOOK-TECH-1020" But I wonder how do professional e-commerce or inventory management system make their SKU? – coder_sam97 Apr 07 '21 at 16:20
  • Well, see the answers to the duplicate question for viable approaches. However, pls do take heed of the warning in Erwin Brandstetter's answer: `This has been asked many times and the general idea is bound to fail in a multi-user environment - and a blog system sounds like exactly such a case. So the best answer is: Don't. Consider a different approach.` – Shadow Apr 07 '21 at 16:32
  • Thanks everyone for their response. I found the solution. – coder_sam97 Apr 07 '21 at 17:13

0 Answers0