开发者

MySQL: universal auto-incremented Item ID AND a customer-unique auto-incremented Item ID

What's the best way to have have each customer have their own set of IDs for items? For example, multiple customers would have开发者_高级运维 an item with ID #101, but in my "items" table, all of those items will have their own primary ID.

I could have a manually incremented ID value in the "customers" table I'd have to lock it on each lookup & manual increment. Seems like that would be a bottleneck.

Thanks.


I would have thought you would need 3 tables to acomplish this:

Customer: Customer_ID (PK)

Item: Item_ID (PK)

CustomerItem: Customer_ID(FK),Item_ID (FK)

Of course this assumes that one customer can have the same item as another. If you just want a Customer to create their own "personal items", the you could have:

Item: [ Customer_ID, Item_ID (auto_inc) ] - Your primary key would then be a composite of Customer ID and an autoincrementing Item_ID?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜