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?
CodePudding user response:
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