Friday, March 23, 2012

question on the primary key

Let say I have 10 columns and 4 of them is a primary keys.
The question is where should I place these 4 columns (with
primary keys)? Is it at the most left?I take it you mean that the 4 column together comprises the PK (i.e., a comp
osite PK, you can only
have one PK but it can be over several columns).
Technically, it doesn't matter. However, when humans read database schemas,
it seems natural to have
the PK as the left-most columns. I.e., it is an esthetic issue.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"mrizal@.padusoft.com.my" <anonymous@.discussions.microsoft.com> wrote in mess
age
news:084e01c48362$1c886130$3a01280a@.phx.gbl...
> Let say I have 10 columns and 4 of them is a primary keys.
> The question is where should I place these 4 columns (with
> primary keys)? Is it at the most left?|||Hi,Tibor
Did the OP mean also sorting columns within PK? I mean if you have primary
key on A,B,C,D ,does it matter a place of the column?
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:eRjvV02gEHA.1656@.TK2MSFTNGP09.phx.gbl...
> I take it you mean that the 4 column together comprises the PK (i.e., a
composite PK, you can only
> have one PK but it can be over several columns).
> Technically, it doesn't matter. However, when humans read database
schemas, it seems natural to have
> the PK as the left-most columns. I.e., it is an esthetic issue.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "mrizal@.padusoft.com.my" <anonymous@.discussions.microsoft.com> wrote in
message
> news:084e01c48362$1c886130$3a01280a@.phx.gbl...
>|||The first column in the composite index (key) should be the one, you most
often query on.
--
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
"mrizal@.padusoft.com.my" <anonymous@.discussions.microsoft.com> wrote in
message news:084e01c48362$1c886130$3a01280a@.phx.gbl...
Let say I have 10 columns and 4 of them is a primary keys.
The question is where should I place these 4 columns (with
primary keys)? Is it at the most left?|||Good point Uri, I read the question as "between all columns in the table". D
an posted a good reply
if the question is "order within the PK columns".
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Uri Dimant" <urid@.iscar.co.il> wrote in message news:u$ThY62gEHA.636@.TK2MSFTNGP12.phx.gbl..
.
> Hi,Tibor
> Did the OP mean also sorting columns within PK? I mean if you have primar
y
> key on A,B,C,D ,does it matter a place of the column?
>
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote i
n
> message news:eRjvV02gEHA.1656@.TK2MSFTNGP09.phx.gbl...
> composite PK, you can only
> schemas, it seems natural to have
> message
>

No comments:

Post a Comment