Composite Primary Keys

Have been looking into using rails but am finding the “Composite
Primary Keys are Bad” thing a tad disturbing (to put it mildly). I
have been working with RDBMS systems for over fifteen years and this
is the first time I have herd the idea questioned. I have cone across
using surrogate keys which mirror the composite key for performance
reasons in VERY big databases but I have never herd the idea
questioned from a logical database design point of view. Apart from
it being easier in rails to use non composite keys has anyone got any
other good reasons not to use them. As far as I am concerned they are
fundamental to RDBMS.

Regards,
Ben

Ben E. - Brussels, Belgium & Bristol, UK
If you have a problem emailing me use
http://www.gurtlush.org.uk/profiles.php?uid=4
(email address this email is sent from may be defunct)

Ben E. wrote:

Have been looking into using rails but am finding the “Composite
Primary Keys are Bad” thing a tad disturbing (to put it mildly). I
have been working with RDBMS systems for over fifteen years and this
is the first time I have herd the idea questioned. I have cone across
using surrogate keys which mirror the composite key for performance
reasons in VERY big databases but I have never herd the idea
questioned from a logical database design point of view. Apart from
it being easier in rails to use non composite keys has anyone got any
other good reasons not to use them. As far as I am concerned they are
fundamental to RDBMS.

They are fundamental to RDBMSes. The problem is that they don’t map so
well from the relational world to the object world so ORMs have to go
through convolutions to handle them. That’s why if you are creating a
“green field” application the recommendation is to use a single column
as the unique key.

This problem is not unique to ActiveRecord. If you look at something
Hibernate, it does support composite primary keys but you have to define
your own “equality” method, even after you specify what columns make up
the composite key.


Michael W.

Ben E. wrote:

Have been looking into using rails but am finding the “Composite
Primary Keys are Bad” thing a tad disturbing (to put it mildly). I
have been working with RDBMS systems for over fifteen years and this
is the first time I have herd the idea questioned. I have cone across
using surrogate keys which mirror the composite key for performance
reasons in VERY big databases but I have never herd the idea
questioned from a logical database design point of view. Apart from
it being easier in rails to use non composite keys has anyone got any
other good reasons not to use them. As far as I am concerned they are
fundamental to RDBMS.

Ben,
you can use composite primary keys in Rails. See
http://compositekeys.rubyforge.org/


Sava C.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs