|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 4:00 PM
Points: 1,910,
Visits: 1,602
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 9:11 AM
Points: 1,422,
Visits: 248
|
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Yesterday @ 10:25 AM
Points: 18,754,
Visits: 12,337
|
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, April 03, 2013 10:05 PM
Points: 584,
Visits: 1,571
|
|
A thought provoking question, but I'm not too keen on the answer. Unless Paul would like to pay for my airfares???
S.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, April 11, 2011 3:52 AM
Points: 18,
Visits: 40
|
|
A Primary Key is always enforced by a clustered index at creation? Correct answer (SQL Server Central) : False
I would just like to add a small point, whenever you create a Primary Key, by default its ALWAYS going to be Clustered. Unless you create a Non Clustered Index Primary Key.
So, when you are saying that IF a Clustered Index already exists, then your what you are mentioning is valid. Else the Primary key, which is usually created at when you are creating the table, would be Clustered index unless specified.
Kindly reply if there is something else to add or I haev misquoted anywhere.
Warm regards, Sameer Chachad.
|
|
|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 5:00 AM
Points: 662,
Visits: 239
|
|
hi sameer,
nice question.... you r question it self has the answwer..
The actual question asked is
A Primary Key is always enforced by a clustered index at creation?
which is not always done, it is enforced by a clustered index only when there is no clustered index existing on that table. If there is an clustered index existing in that table, the primary key u r going to create will be enforced by a non clustered index.
please notice the word "always" in the question...
Anil Kubireddi
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 9:23 AM
Points: 1,288,
Visits: 2,996
|
|
A Primary Key is created by defaut as a Clustered Index, unless a Clustered Index already exists on the table, which is really to say that the Clustered Index does not have to necessarily be the Primary Key. It is the semantics of how you are phrasing the question that is a little tricky and confusing for some. However, as you state Paul in your explanation, the more important piece to emphasize here is the reasoning of where you decide to put your Clustered Index on your table. Application functionality can drive this at times and a PK is not always the first choice . That said, primary keys do tend to make make good candiates for the CI simply because they and their auto-incrementing data (singleton PK columns are many times IDENTITY columns as well, although not required to be) automatically satisfy two main requirements of a Primary Key. NO NULLS and Unique data, where Unique Keys can allow one NULL and are created Non-Clustered by default and can have more than one UK on a table I believe. Both PK's and UK's can be made up of more than one column as well. . :)
"Technology is a weird thing. It brings you great gifts with one hand, and it stabs you in the back with the other. ... "
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 3:21 AM
Points: 5,244,
Visits: 7,062
|
|
sameerchachad 69959 (3/9/2010) A Primary Key is always enforced by a clustered index at creation? Correct answer (SQL Server Central) : False
I would just like to add a small point, whenever you create a Primary Key, by default its ALWAYS going to be Clustered. Unless you create a Non Clustered Index Primary Key.
So, when you are saying that IF a Clustered Index already exists, then your what you are mentioning is valid. Else the Primary key, which is usually created at when you are creating the table, would be Clustered index unless specified.
Kindly reply if there is something else to add or I haev misquoted anywhere.
Warm regards, Sameer Chachad.
The answer given by Paul is correct but incomplete. The explanation correctly describes what happens if you do not specify a clustering option for the PRIMARY KEY constraint, but it doesn't include the extra possibilities that arise from adding the keyword CLUSTERED or NONCLUSTERED to the constraint.
These are the scenarios that are possible when a PRIMARY KEY constraint is created:
1) No clustered index exists for the table, no clustering option specified for the constraint --> Clustered index is created. (This is probably the most common scenario) 2) No clustered index exists for the table, CLUSTERED option specified for the constraint --> Clustered index is created. 3) No clustered index exists for the table, NONCLUSTERED option specified for the constraint --> Non-clustered index is created. 4) A clustered index already exists for the table, no clustering option specified for the constraint --> Non-clustered index is created. 5) A clustered index already exists for the table, CLUSTERED option specified for the constraint --> No index created; error 1902 raised; constraint not created. 6) A clustered index exists for the table, NONCLUSTERED option specified for the constraint --> Non-clustered index is created.
Still, a great question. I really hope that Paul and Kimberly continue to submit questions, even if they don't have a seminar to promote.
(edit: small but important typo in option 6 - thanks, Shaiju C.K., for alerting me to it)
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Friday, December 21, 2012 5:24 AM
Points: 366,
Visits: 436
|
|
trickey question...already existing Clustered Index just went off from my mind and I answered TRUE...I was wondering why Paul would have asked such a simple question and w/o giving it a 2nd thought I happened to answered it wrong...
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Thursday, December 13, 2012 1:10 AM
Points: 67,
Visits: 40
|
|
Paul Randal,
When you ask\ write any question mention your assumption.
|
|
|
|