Michael
Michael

Reputation: 107

MySQL Incrementing ID/UUID Question

i'm attempting to create a table with an incremental ID. This isn't the simple id with AUTO_INCREMENT. In fact, the exact ID that i'm trying to work with is:

test.script.1/person.n (where n is an incrementing number)

Specifically, I have a table structured as:

ID | fname | lname | gender | age |

Each person that I add in, I wish to have and incremental ID. So for person 1, it would be test.script.1/person.1 and then test.script.1/person.2 for the second entry and so on and so forth.

Is it possible to do this? I have searched for a while now in Google, but I do not think I am searching for the right thing. My apologies if there isn't that much information, and it is a simple question, I just don't know what to look for. Please advise.

Thanks guys!

Upvotes: 1

Views: 277

Answers (1)

davek
davek

Reputation: 22925

You can use an autoincrementing field together with a trigger to populate the actual field you wish to use for your reference.

Something like this:

CREATE TRIGGER set_my_uuid AFTER INSERT ON myTable
FOR EACH ROW
BEGIN
SET NEW.uuid_ref_col = concat('test.script.1/person.', NEW.my_auto_increment_col)
END
;

where my_auto_increment_col is a standard autoincrement column in the table.

Upvotes: 1

Related Questions