Reputation: 4254
I'm working on a database that uses integers as primary keys for a number of tables. I'd like to make the primary keys relatively difficult to guess — they needn't be super-tight, just not incrementing integers in the low hundreds. Since I'm retrofitting this into existing schemata, with existing data, changing the datatype of the primary key (integer
) is not feasible. What I'm wondering is how best to generate the IDs. So far, I can think of these options:
UUID()
and convert them to integer.CONCAT(UNIX_TIMESTAMP(),SUBSTRING(RAND() FROM 3 FOR 6))
I'm open to other suggestions, too.
I'd appreciate any thoughts you can offer.
Thanks, Ross
Upvotes: 2
Views: 586
Reputation: 14091
Why are you doing that? You'll mess up the way the data is physically stored. Use secondary index and make it a GUID if you need to pass it trough URLs for lookups.
Upvotes: 4