db-ddlutils-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Dudziak" <tom...@gmail.com>
Subject Re: SQL Exception on trying to add some foreign keys constraints with DdlUtils
Date Wed, 30 May 2007 17:24:15 GMT
On 5/28/07, Ricardo Palomares <rpmdisguise-java@yahoo.es> wrote:

> <table name="L10N">
>   <column name="ID" primaryKey="true" required="true" type="INTEGER"
>    size="10" autoIncrement="true"/>
>   <column name="L10NCODE" primaryKey="false" required="true"
>    type="VARCHAR" size="10" autoIncrement="false"/>
>   (...other internal fields...)
>   <unique name="L10N_BY_CODE">
>     <unique-column name="L10NCODE"/>
>   </unique>
> </table>
>
> would it be OK if I just turn L10NCODE on as part of the primary key?
> (It looks a bit weird to me, to be honest).
>
> Actually, I put ID there just to have a primary key definition in a
> consistent way through the whole database, but I could well live with
> L10NCODE being the PK (and completely drop ID field in that table),
> since it will be unique by design and the table itself would likely
> never grow up over 100 records (being 2 or 3 the more usual figure).

Well, the question is, do you really need the ID field (i.e. does it
serve a purpose in your application) or is it just an artificial field
(i.e. only used in the database or for lookup of rows).
If the latter and L10NCODE has to be unique anyways, then IMO it does
not really make sense to have an additional ID field with no real
purpose.
Think of it this way: the primary key sort-of defines the identity of
the row. So, if L10NCODE uniquely defines a row in the table (and thus
could be used for primary key), then all you have to ask yourself is:
does it make sense in your application to have L10NCODE be the primary
key ? This is not so much a database question but a application design
question. Imagine that you have multiple unique columns in the table,
which one would you choose for the primary key (if any) ?

Tom

Mime
View raw message