PK Vs Clustered Index

  • If i have a clustered index on a table withtout any PK, does it satisfy the purpose of PK.

  • Primary key enforces uniqueness and also doesnt allows NULL.

  • Tara (6/3/2009)


    If i have a clustered index on a table withtout any PK, does it satisfy the purpose of PK.

    The primary key in fact is a concept in relational databases. The objective of the PK is to have no repeated records in a table based on primary key fields. By the way, if you have a UNIQUE index containing some fields, it will satisfy the uniqueness criteria but you have to ensure that these fields can not contain null values. The fact of index being clustered or nonclustered is not relevant for the purpousses of PK.

  • that means both will have uniqueness but the only differnce is clustered index will allow NULL but PK doesnt.

  • if you have a UNIQUE index containing some fields

    that means both will have uniqueness but the only differnce is clustered index will allow NULL but PK doesnt.

    You need to define it as UNIQUE....

    CLUSTERED means data is physicaly ordered in the table..Doesn't mean that it's unque.

  • Tara (6/3/2009)


    If i have a clustered index on a table withtout any PK, does it satisfy the purpose of PK.

    Simply put, no. They're not the same thing.

    Clustered indexes, even unique clustered index, will satisfy many of the mechanical purposes of a PK, but it's not the same concept.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Introducing Primary Key is enforcing business rules concept.(its more logical concept)

    Enforcing Clustered indexes is in regard to your maintenance of your table(Searches, Sorting of ur table, more physical concept)

  • At the same time, primary key creates the clustered index automatically if no clustered index already exists

  • bugop (6/3/2009)


    At the same time, primary key creates the clustered index automatically if no clustered index already exists

    That is not rigorously correct...

    As many people has said, the primary key is a logical concept. When you set the primary key using the Management Studio visual interface then it enforces the primary key restriction creating a clustered index (if no clustered index already exists).

  • FelixG (6/3/2009)


    bugop (6/3/2009)


    At the same time, primary key creates the clustered index automatically if no clustered index already exists

    That is not rigorously correct...

    As many people has said, the primary key is a logical concept. When you set the primary key using the Management Studio visual interface then it enforces the primary key restriction creating a clustered index (if no clustered index already exists).

    That's the default behavior. You can specify "nonclustered" on a PK explicitly, in which case it will simply create a unique index, even if there's no clustered index on the table.

    But now we're off into essoterica.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply