Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««23456»»

Is a Primary Key an index? Expand / Collapse
Author
Message
Posted Thursday, July 17, 2014 8:03 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Today @ 3:40 AM
Points: 588, Visits: 2,554
@Sergei
Please correct me if I'm wrong but I'd always believed a primary key was enforced by a constraint which was implemented by means of both a UNIQUE index and NOT NULL constraints on all the participating columns.
The reason for my pedantry is nothing to do with metaphysics but all to do with foreign keys, and candidate keys. Hmmm. I've maybe got a few more QOTDs to do, even if I'm really just asking myself.



Best wishes,

Phil Factor
Simple Talk
Post #1593605
Posted Thursday, July 17, 2014 8:24 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, August 21, 2014 8:15 AM
Points: 490, Visits: 935
Interesting also, is that when you create a PK on a table, in SSMS that it lists that PK under Indexes and not under Constraints.
Post #1593622
Posted Thursday, July 17, 2014 9:09 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 12:27 AM
Points: 1,321, Visits: 632
pmadhavapeddi22 (7/15/2014)
This is my understanding. primary key is a constraint not an index, but it creates an index automatically by default, but primary key is called a constraint not an index though. so I got it correct (though I had to think little bit)

Good question

Good analytical thinking
Post #1593671
Posted Thursday, July 17, 2014 9:16 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 12:27 AM
Points: 1,321, Visits: 632
Steve Lund (7/17/2014)
Interesting also, is that when you create a PK on a table, in SSMS that it lists that PK under Indexes and not under Constraints.

True, although PK is considered as Constraint not Index
Post #1593675
Posted Thursday, July 17, 2014 2:04 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:51 AM
Points: 13,294, Visits: 11,083
Sergiy (7/16/2014)
Koen Verbeeck (7/16/2014)
So it is 100% possible to decouple the primary key from the index

Can you illustrate how?


Easy peasy. I draw a table diagram in Visio and declare the combination of a few columns to be the primary key.
(in other words, I am creating the logical design)
Where do you see an index?

The index we are talking about is the manifistation of the primary key on the physical level.
On the logical level however, I simply do not care how it is implemented at the physical level. It does not matter.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1593830
Posted Thursday, July 17, 2014 10:38 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 8:19 AM
Points: 111, Visits: 41
Well, according to SQL Server BOL:

PRIMARY KEY
Is a constraint that enforces entity integrity for a specified column or columns through a unique index. Only one PRIMARY KEY constraint can be created per table.
Post #1593900
Posted Thursday, July 17, 2014 11:53 PM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Monday, October 13, 2014 8:08 PM
Points: 4,573, Visits: 8,353
Phil Factor (7/17/2014)
@Sergei
Please correct me if I'm wrong but I'd always believed a primary key was enforced by a constraint which was implemented by means of both a UNIQUE index and NOT NULL constraints on all the participating columns.

Not quite.
But I'll write about it later in a separate post.

The reason for my pedantry is nothing to do with metaphysics but all to do with foreign keys, and candidate keys. Hmmm. I've maybe got a few more QOTDs to do, even if I'm really just asking myself.

If we're talking about foreign keys and candidate keys there is no diffeence between PK and UNIQUE.
I often use UNIQUE instead of PRIMARY KEY when I need to allow NULL into a PK column.
Post #1593909
Posted Thursday, July 17, 2014 11:55 PM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Monday, October 13, 2014 8:08 PM
Points: 4,573, Visits: 8,353
Steve Lund (7/17/2014)
Interesting also, is that when you create a PK on a table, in SSMS that it lists that PK under Indexes and not under Constraints.

Look under "Keys".
It's another silly thing in SSMS, indicating that it was designed by people who did not have a clue.
Post #1593910
Posted Friday, July 18, 2014 12:03 AM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Monday, October 13, 2014 8:08 PM
Points: 4,573, Visits: 8,353
Koen Verbeeck (7/17/2014)
Sergiy (7/16/2014)
Koen Verbeeck (7/16/2014)
So it is 100% possible to decouple the primary key from the index

Can you illustrate how?


Easy peasy. I draw a table diagram in Visio and declare the combination of a few columns to be the primary key.
(in other words, I am creating the logical design)
Where do you see an index?

I do not see a primery key here either.
I do not even see a database.
It's just a set of drawings, labels, indicated intentions.

As soon you try to turn it into an actual database and actually create that PK the corresponding index will be there.
Post #1593912
Posted Friday, July 18, 2014 12:21 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 6:56 AM
Points: 5,180, Visits: 12,032
Sergiy (7/18/2014)
Koen Verbeeck (7/17/2014)
Sergiy (7/16/2014)
Koen Verbeeck (7/16/2014)
So it is 100% possible to decouple the primary key from the index

Can you illustrate how?


Easy peasy. I draw a table diagram in Visio and declare the combination of a few columns to be the primary key.
(in other words, I am creating the logical design)
Where do you see an index?

I do not see a primery key here either.
I do not even see a database.
It's just a set of drawings, labels, indicated intentions.

As soon you try to turn it into an actual database and actually create that PK the corresponding index will be there.


You appear to be suggesting that a primary key does not and can not exist unless it is physically implemented in a database - is that the case?

Meaning, presumably, that you object to a basic database design document using the term 'primary key'.

Perhaps instead you refer to a relation's "default unique-row identifier(s)". Does the job, I suppose.



Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
Post #1593916
« Prev Topic | Next Topic »

Add to briefcase «««23456»»

Permissions Expand / Collapse