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?