Mysql – Creating a single recid stream for multiple tables

auto-incrementmariadbMySQL

I'd like to have a single reservoir of RECIDs to apply across multiple tables.

Obviously I can do that by creating a table with a single auto-increment field and inserting every time I need a new RECID.

But that produces a lot of 8-byte+ records that have no real purpose.

A little resident function to delete each record when produced would keep the table pruned back, but I'm wondering whether there's a cleaner way to get to the same goal.

Best Answer

You don't need a "reservoir", rather a way to generate a unique number.

Usually it is sufficient to give that task to one table you already have, and use AUTO_INCREMENT there, plus LAST_INSERT_ID().

But it you really need a sequence generator: