Say I have a table with a primary key a_id and foreign key b_id.
It is important that a_id and b_id never intersect, i.e. it should never be the case that there exists an a_id = b_id.
What would be the best way to implement this? Could I somehow do this on the database end (mySql), or should this be ensured programmatically? If I ensure this programmatically, is it bad practice to insert a number for a primary key (rather than have the database autoincrement it)? I assume I would just create a routine that checks the latest primary key and simply increments it (and I would also need to ensure that the range of a_id never intersects the range of b_id). Any suggestions?
You could create another table that has the auto-increment field. Upon insertion of a record, it would insert into that “key table” and use the referenced values there. So if you have two globally unique keys in one table each insert would be two key inserts. This solution would scale beyond 2 as well.
But I have to ask: Why?