Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Understanding PK index
Message
 
 
À
16/01/2016 06:01:54
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
01629831
Message ID:
01629836
Vues:
31
>>Hi,
>>
>>When I make a field to be a Primary key (the field is Int type and Identity is set ON), SQL server creates a KEY named PK_Table_Name and at the same time it creates a Unique Non-Clustered index of the same name (e.g. PK_Table_Name). Will SQL use this index when optimizing searches that include the PK field?
>>
>>The reason I am asking is that I noticed that - somehow - when I was creating the table I created a separate Non-Unique and Non-Clustered Index On the same fields (which is the PK field). Therefore, my question is, would it be Ok to delete this "extra" index that I created?
>
>The "somehow" is just a bit of rubbish introduced by SSMS, which generates script for this additional key, for reasons unknown. If you just create a table with a primary key and do nothing else in a script, no additional indexes are created. Because even SQL server does only what you tell it to do. So yes, just delete that index.
>
>Now why would SSMS create this extra index is beyond me, and I've noticed that it does so. Actually, this is one more on the long list of complaints (if not outright bugs found) that I will add to my list of "what's wrong with SSMS".

Thank you for the explanation. In truth, in my case, I think I am to blame. That is, the "somehow" is me. After I posted the message I was going through my memory of working on this table. And I believe that the first version of this table the PK field was not a PK but a regular column. That is, I created a table but didn't make any column to be a PK. So I decided to add an index on this column. Later, when I learned a little more, I converted this column to a PK, which created the index PK_TABLE_NAME. But I never deleted the one I created before. So I will delete it now.
Again, thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform