Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Primary keys and clustered indexes
Message
De
29/06/2006 19:13:21
 
 
À
29/06/2006 17:38:14
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Conception bases de données
Divers
Thread ID:
01132920
Message ID:
01132946
Vues:
12
>Hello everyone,
>
>Assume a header/detail situation:
>
>Invoices table:
>Primary key: invoiceID (unique integer)
>
I sit next to a DBA now. I asked him. He reccommended option 3. So selects will be much faster, since the table will be in that order.

>InvoiceDetails table:
>lineID (unique integer)
>invoiceID (integer, relates to invoices table)
>
>The lineID of the detail table is good enough to be the primary key. However, all (or almost all) joins on this table will involve the invoiceID. So it makes sense for invoiceID to be part of a clustered index. For the most part, invoices will be inserted sequentially. Deletions shouldn't happen.
>
>In many cases, but not all, a query involving the invoiceDetails would be returning all the rows from that invoiceID.
>
>Some options I see for the detal table:
>
>1) primary key: lineID, but with a non-clustered index. clustered index on invoiceID.
>
>2) primary key: lineID, but with a non-clustered index. A clustered index on invoiceID + lineID.
>
>3) primary key: invoiceID + lineID, with clustered index on the combination.
>
>Is the best option one of these three? Or something else?

(On an infant's shirt): Already smarter than Bush
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform