Is there a way to make mysql hash the auto increment values for its tables? For example with md5?
id - name 1 - New York 2 - Chicago 3 - Sydney 4 - Berlin
what I'm trying to get
id - name c4ca4238a0b923820dcc509a6f75849b - New York c81e728d9d4c2f636f067f89cc14862c - Chicago eccbc87e4b5ce2fe28308fd9f2a7baf3 - Sydney a87ff679a2f3e71d9181a67b7542122c - Berlin
Thanks in advance
EDIT:
I think I need to clarify the question a little more, what im trying to do is not Call the ID's but Insert them. In the moment the ID column is an int field which I will change to varchar.
I want to save the identifiers as Hashed in the DB not call them with mysql SELECT. Thanks
MySQL
Docs say..A best bet would be to do this...
or to run a
TRIGGER
Something like ... (Not 100% correct... just giving you an idea)
The Answers here brought up an Idea in me.. I think that will work as the best solution for now.. but if there is someone who knows an easier way I'm glad to hear it.
Solution:
Create a new table with an auto increment field like id or count, which you will always increment first and use the last ID out of that table to hash it for the primary field of your other table.
Maybe i did not understand the question, but this is my opinion:
I think you try to create a hash table. So insert id field as hash of your data (md5(name)).
But if not, use a table trigger to generate field hash after insert.
All the answers above lack a good understanding of the need to use hashed id's.
Hashing the auto increment id violates the whole concept. The concept you want to reach is that the next id will be unpredictable from the previous.
In the idea of hashing the id the next id of the md5( 1 ) is the md5( 2 ).
If you use the names that helps.
It would be best to create the hash from several fields. The fields together should be unique to create a unique hash.
If you really need this, for some reason, you can achieve it with a help of a separate table for sequencing and a
BEFORE
triggerTable schemas:
The trigger
Now you can insert rows into your
table1
tableor select
Here is SQLFiddle demo