Tuesday, March 20, 2012

Primary key at the beggning of each record

Are primary keys always the first columns in each record? What's the
divantage of having them for example in the middle of the records? what
happens?
ThanksOnly cosmetics. No technical difference. Check out what standards you want t
o follow, if there
already is a standard in place etc. From a technical standpoint, column orde
ring is irrelevant
(since no-one should do SELECT * or INSERT without a column name list in pro
duction code). Most
people find tables easier to read with PK as the first column though, I'm gu
ilty as charged, for
instance.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"J-T" <J-T@.microsft.com> wrote in message news:O5lObkRbFHA.3932@.TK2MSFTNGP12.phx.gbl...[col
or=darkred]
> Are primary keys always the first columns in each record? What's the di
vantage of having them
> for example in the middle of the records? what happens?
> Thanks
>[/color]|||As an add-on to Tibor's statement...the ordering of the columns used in the
PK IS important as SQL Server will automatically add a clustered index
(default) for each PK...first column if composite key is used should be most
selective.
HTH
J
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:%23J0uHoRbFHA.1660@.tk2msftngp13.phx.gbl...
> Only cosmetics. No technical difference. Check out what standards you want
> to follow, if there already is a standard in place etc. From a technical
> standpoint, column ordering is irrelevant (since no-one should do SELECT *
> or INSERT without a column name list in production code). Most people find
> tables easier to read with PK as the first column though, I'm guilty as
> charged, for instance.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "J-T" <J-T@.microsft.com> wrote in message
> news:O5lObkRbFHA.3932@.TK2MSFTNGP12.phx.gbl...
>|||<
Are primary keys always the first columns in each record?
>
Not necessarily.
<
What's the divantage of having them for example in the middle of the
records? what happens?
>
To my knowledge, there are no physical divantages. However, people
are familiar with the first columns being the primary key.
When IBM made available the Indexed Sequential Access Method (ISAM) in
the 1960s, there was a restriction that the unqiue index bits had to be
at the start of the record.
This restriction has now become a tradition.
Carl Federl
Please post DDL (create table) with datatypes, primary and foreign keys.
*** Sent via Developersdex http://www.examnotes.net ***|||what do yuo mean by *most selective*?
Thanks
"Jerry Spivey" <jspivey@.vestas-awt.com> wrote in message
news:eLiOQsRbFHA.1504@.TK2MSFTNGP15.phx.gbl...
> As an add-on to Tibor's statement...the ordering of the columns used in
> the PK IS important as SQL Server will automatically add a clustered index
> (default) for each PK...first column if composite key is used should be
> most selective.
> HTH
> J
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote
> in message news:%23J0uHoRbFHA.1660@.tk2msftngp13.phx.gbl...
>|||most unique - increases the likelyhood that the index will be utilized to
increase the performance of queries.
"J-T" <J-T@.microsft.com> wrote in message
news:uiqdy2RbFHA.3384@.TK2MSFTNGP09.phx.gbl...
> what do yuo mean by *most selective*?
> Thanks
> "Jerry Spivey" <jspivey@.vestas-awt.com> wrote in message
> news:eLiOQsRbFHA.1504@.TK2MSFTNGP15.phx.gbl...
>

No comments:

Post a Comment