Need suggestions to get a unique index keys for two or more tables on mysql
Usually, I use auto_increment attribute to get an unique key/id for each row on a single table to use as a primary index. Now I have two tables and unfortunately auto_increment can't create a new key using the last id/key on another table to keep all the k开发者_Python百科eys/id unique in both. If I'll use auto_increment on both index columns, the possibility to have two identical ID is assured! There is a easy way to do it?
At least from a perspective of relational database design, your requirement seems unsound. You ought to create a separate table with the common auto_increment field and point to that from the other two tables with foreign keys.
If you have:
- table A with ids 1,2,3.
- table B with ids 1,2,3.
Then you already have the following (virtual) unique identifiers:
- A1, A2, A3, B1, B2, B3
You don't need to make any changes to your database. This is purely a presentation issue.
精彩评论