[sqlalchemy] Re: Multi-column primary key
Well, that's simple :) On Mar 13, 1:20 am, Michael Bayer [EMAIL PROTECTED] wrote: use a composite primary key - just mark each column with 'primary_key=True'. On Mar 12, 2007, at 2:28 PM, Mikkel Høgh wrote: Hi there, I'm trying to make a small (open source) inventory tracking system with TurboGears and SQLAlchemy, and I have a little problem with how I should implement the database part. I think the best idea would be to have different sequences for each type of item tracked, so spork number 543 would be SPRK-0543. Now, one could of course create a different table for each type of item stored, but that means that creation of new types includes modifications to the database structure and (even worse) the database model. So I thought of just putting it all in a single table. The way I see it, there's three different ways to do that, and I cannot discern which is best: 1) Use a normal int primary key and have item_number and item_type as indexed columns 2) Use a string primary primary key, containing the full item designation (SPRK-0543) 3) Use a multi-column primary key with item_type and item_number The way I see it, #3 would be preferable, but is that possible with SQLAlchemy - I can use UniqueConstraint to make sure the combination is unique, but does that perform well, and can it be a primary key? In any case, I'm not decided yet, so if you have any advice on how to best accomplish my goal, I'd appreciate if you'd help me :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Multi-column primary key
use a composite primary key - just mark each column with 'primary_key=True'. On Mar 12, 2007, at 2:28 PM, Mikkel Høgh wrote: Hi there, I'm trying to make a small (open source) inventory tracking system with TurboGears and SQLAlchemy, and I have a little problem with how I should implement the database part. I think the best idea would be to have different sequences for each type of item tracked, so spork number 543 would be SPRK-0543. Now, one could of course create a different table for each type of item stored, but that means that creation of new types includes modifications to the database structure and (even worse) the database model. So I thought of just putting it all in a single table. The way I see it, there's three different ways to do that, and I cannot discern which is best: 1) Use a normal int primary key and have item_number and item_type as indexed columns 2) Use a string primary primary key, containing the full item designation (SPRK-0543) 3) Use a multi-column primary key with item_type and item_number The way I see it, #3 would be preferable, but is that possible with SQLAlchemy - I can use UniqueConstraint to make sure the combination is unique, but does that perform well, and can it be a primary key? In any case, I'm not decided yet, so if you have any advice on how to best accomplish my goal, I'd appreciate if you'd help me :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---