[Pharo-project] relational database and id field

Benoit St-Jean bstjean at yahoo.com
Thu Apr 7 14:41:38 CEST 2011

Hi Alexandre,

Normally, you should always have a primary key to uniquely identify a record in 
a database table.  If you have an attribute (or a set of attributes) that can 
uniquely identify your ComicBook, you don't need an id field.  BUT, if you tell 
me you're going to store lots and lots and lots of those ComicBook instances, 
having an id (integer) as the primary key has potential non-negligeable 
advantages over, say, something like a name.  Mainly because an id (let's 
suppose it's an INT) takes way less storage than say a name (VARCHAR(30) for 
instance) and thus more index records can fit into the key buffer in memory.

To be brief

1) yes, always provide a primary key
2) if you have already A primary key (even a composite one)
    2a) if you need performance and are gonna store LOTS of those objects, the 
smaller the key the better so you could create a surrogate key (the id key) 
instead of using the "real" primary key
    2b) if performance is not an issue, you can use what is already available 
that uniquely identifies your object (row) in the database table

P.S.  Are you using a particular OO-RDBMS framework?  

Benoit St-Jean
Yahoo! Messenger: bstjean
A standpoint is an intellectual horizon of radius zero.
(Albert Einstein)

From: Alexandre Bergel <alexandre.bergel at me.com>
To: Pharo Development <Pharo-project at lists.gforge.inria.fr>
Sent: Thu, April 7, 2011 9:19:03 AM
Subject: [Pharo-project] relational database and id field


Since there are some experts in databases here, I ask a general question about 
Assume that I have to use a relational database to store, let's stay instances 
of Stef's ComicBook class.
Should the class ComicBook have a field id to uniquely identify a book?

Alexandre Bergel  http://www.bergel.eu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gforge.inria.fr/pipermail/pharo-project/attachments/20110407/69b609fe/attachment.htm>

More information about the Pharo-project mailing list