How to increment the varchar() code field automatically in Mysql?

Asked

Viewed 225 times

0

I need to do a stock control, where the code of the products should be varchar, because the code will be formed by the abbreviated name of the product category followed by a sequential number, so I will not use the column product_ID who’s kind int, but I will use the product_codev, that is varchar, and I need it to be auto-incrementable. As I do, it has as with triggers?

1 answer

0


Let product_ID as auto_increment and make a Trigger of after insert. So you can ride the product_codev as you see fit.

Now if I can give you a suggestion, I think this product_codev could be mounted on the application, since apparently it is something to present to the user and not to ensure the consistency of the data.

  • Okay, thank you so much for the answer, I think I will make the product_code in the application, the product_id is already working anyway! I can’t vote yet on your answer because I’m a new user

  • You can accept as the correct answer ;p

Browser other questions tagged

You are not signed in. Login or sign up in order to post.