Quantcast
Channel: How to use 2 auto increment columns in MySQL phpmyadmin - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 5

Answer by Arthur Tarasov for How to use 2 auto increment columns in MySQL phpmyadmin

$
0
0

I just ran into this problem and would like to contribute to the answers. I used Ypercube's answer to solve it, but in a slightly different way. First though,

Why do you need the second auto increment column besides ID?

There are some objects, the quantity of which can be pretty sensitive corporate info. For example, I may not want user_id 37 to suggest that I only have 37 users on my website. Number of claims, number of purchases, number of anything that is good or bad that you don't want users, competitors, or regulators to know.

Yet it is useful, at least in my case, to assign a unique publicly available number to these objects so that I can manage them easier with user input. For example, this question on SE has a number 35449 and I can get it by typing this number into browser: https://dba.stackexchange.com/questions/35449

And finally I don't want to create any complex overhead trying to obscure id's. Auto increment of a number greater than ID will do.

So that's the problem. Ypercube's answer has a pretty cool solution, just add a constant to the id. Only I did it in PHP in my case with an extra query and put it in a separate function so I can easily keep track of it and it doesn't get tightly coupled with the rest of SQL. It is slower but easier to manage as for me.

Note, if trying to lessen appeared quantity of something negative, like complaint_id or refund_id, don't subtract as you may go into negative, just add a huge random number, in billions+ with no consecutive zeroes (e.g. id + 159035466234) that will make it clear that it has nothing to do with quantity of those objects.


Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>