Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Primary Keys: surrogate or composite??
Message
De
21/03/2000 17:28:36
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Primary Keys: surrogate or composite??
Divers
Thread ID:
00348623
Message ID:
00348623
Vues:
70
Hi all,

I'm having a discussion with my boss and a fellow co-worker who is a dba about the usage of surrogate keys for primary keys in tables (he calls them "artificial keys").

My argument is for using single-field sequence numbers as primary keys for every table and using single-field foreign keys in any child tables (which would also contain their own single-field primary keys). My reasoning is that these sequence key fields will never change because they're not part of natural data. I'm also arguing that this approach is more efficient for SQL joins, indexed seeks, etc.

My colleagues on the other hand are saying that it's a mistake to use "artificial" keys because they aren't self documenting in the code. They even argue for composite keys to be used when multiple fields uniquely identify a record.

For example, let's say I have a division table, a department table that is a child of the division table, and a work center table that is a child of the department table. My colleagues are saying that the keyfields should be designed in the following fashion:

DIVISION TABLE
Field 1: Division # or name
Primary Key: Division # or name

DEPARTMENT TABLE
Field 1: Division # or name
Field 2: Dept # or name
Primary Key: Division # + Dept #

WORK_CENTER TABLE
Field 1: Division # or name
Field 2: Dept # or name
Field 3: Work Center # or name
Primary Key: Division # + Dept # + Work Center #

My suggestion would look like the following:

DIVISION TABLE
Field 1: PKDivision (Integer)
Field 2: Division # or name

DEPARTMENT TABLE
Field 1: PKDepartment (Integer)
Field 2: FKDivision (Integer)
Field 3: Department # or name

WORK_CENTER TABLE
Field 1: PKWorkCenter (Integer)
Field 2: FKDepartment (Integer)
Field 3: Work Center # or name

I always thought that the going rule of thumb is that surrogate (artificial or auto-incrementing) keys are the way to go. I'm curious to know what the going consensus is here on the UT?

Thanks!

-JT
Jeff Trockman, MCP
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform