Re: integer id columns for all tables
From: Alexandr Savinov <spam_at_conceptoriented.com>
Date: Tue, 29 Aug 2006 11:01:25 +0200
Message-ID: <ed0vpb$r3o$1_at_f1node01.rhrz.uni-bonn.de>
Date: Tue, 29 Aug 2006 11:01:25 +0200
Message-ID: <ed0vpb$r3o$1_at_f1node01.rhrz.uni-bonn.de>
garhone schrieb:
> Hi,
>
> Someone with greater expertise than I recently told me that it is best
> to have an integer primary-key for all tables in a database, even if
> the table already has some non-integer primary key, or some sort of
> composite primary key. If there is already a non-integer key, then
> create a new sequence column and set that as the primary key.
>
> Does anyone have an opinion on this and why?
Here are a number of principles for designing identifiers:
- An entity may well exist without properties but not without identifiers.
- An identifier is the first thing to be created before actually the entity itself is created. In other words, we create an identifier and only after that (and if it is really needed) the corresponding entity is created.
- Identifiers have to be constant (in contrast to properties). If you use a kind of system identifier then you are guaranteed then nobody can change it or otherwise misuse.
- Identifiers should not be meaningful because they are intended to be manipulated by the software rather than by users (with the exception of some well known identifiers used for bootstrapping). So identifiers should be hidden from the users.
- Identifiers should be defined before any properties exist. Such a structure will have only identifiers for accessing empty entities. After that we can add meaningful properties. This discipline can ensure the separation between these two concerns.
- If you need uniqueness then use the corresponding constraint. Frequently the need for uniqueness in a property leads to the conclusion that it should be used as an identifier.
-- http://conceptoriented.comReceived on Tue Aug 29 2006 - 11:01:25 CEST