0

I want to autogenerate sequence for a primary key field as a custom Id with auto-increment properties. For example, Id list should be like [P001, P002, P003...]. How can I generate this from normal Id column or otherwise?

CREATE TABLE `product` (
  `id` integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `name` varchar(45) DEFAULT NULL
};

I have checked and found out solutions to do so in SQL. But I need to know the MySQL workaround for this.

My situation is similar to this question, but it doesn't work on MySQL. How to create a custom auto generated ID number for a primary key column?

Shadow
  • 33,525
  • 10
  • 51
  • 64
moonchild_
  • 17
  • 10

1 Answers1

1

You can achieve this by creating a TRIGGER. Check out this question/answer How to make MySQL table primary key auto increment with some prefix

slashroot
  • 773
  • 1
  • 4
  • 13