Return inserted value after INSERT

Asked

Viewed 356 times

0

I have a following table:

CREATE TABLE tblUser (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    uuid VARCHAR(24) NULL,
    name VARCHAR(256) NULL
}

I’m inserting a uuid random to be a unique identifier directly within my database using:

select substring(MD5(RAND()) FROM 1 FOR 24

This query just above me returns a value like this: c4b912f99fc0c2e82526043c

In PHP I can return the last id inserted into the bank using mysql_insert_id(), but I would like in my INSERT return me the value ofUUID without having to create a SELECT. Is there any way to do that?

  • Do you think you can accept the answer? Or do you need something else?

  • Hi @bigown, only your second sentence of the answer answered my question, but without any reference. But of course I know you’re quite a reference (I’m not sucking up - I think). The first sentence I will take as a suggestion, important, but not as an answer. I realized that in fact my attempt to generate a UUID - which is not uuid - is somewhat flawed, because, as they said and another question: "lightning always falls in the same place when it has to fall". Thank you for the teaching, for me and for many people here. I have a lot to learn and I will continue to persist in this.

1 answer

1


There’s no way to figure out what was inserted into INSERT except the last ID, has to do the SELECT even.

  • Ola bigown, the UUID pattern is: 6ccd780c-baba-1026-9564-0040f4311e29. This way, I didn’t want it to generate the value with the dash: -. For this reason I am doing it this way. If I use the UUID function, I would make it have only 24 characters?

  • But that’s UUID, what you’re generating is not. UUID has 32 useful characters and has its own generation form. What you can do is use another function together to remove the strokes that ends up forming 36 characters in total. There is a shorter form, but I don’t think it’s appropriate for what you’re doing. Although I don’t even understand why ID and UUID.

  • Well, actually I did NOT want to use a sequential value for the user identifier, and for that reason I am using UUID (which is not uuid as you just said above). So I wanted the user identifier to be only 24 characters long. I’ve seen that has UID_SHORT() which has 17 characters, but is only numeric according to the mysql documentation.

  • But you’re using a sequential. I don’t know if I would use the reduced version to produce something unique. You have to decide whether you want a unique, universal ID or a random, sequential ID.

  • My table is another, I put this as an example, because the one I wanted to solve was another, however we came to this subject. But since you want to help me, I am DECIDED to have a ID whatever, non-sequential with 24 characters and not only numerical. Can you help me? Think I should ask another question ?

  • Maybe, I think what was asked here was answered, since it wasn’t even about UUID :)

  • Okay. I will fly...

Show 2 more comments

Browser other questions tagged

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