SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Index defaults 2


Index defaults 2

Author
Message
jfogel
jfogel
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1021 Visits: 1176
Got it right because I know creating an FK doesn't create and index and you can't specify such a thing in the syntax. It has been odd lately that I've been getting these Jedi mind trick questions right and at times I get the simple ones wrong just because I didn't read is close enough.

Cheers
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)

Group: General Forum Members
Points: 67009 Visits: 18570
Thanks Hugo.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

jfogel
jfogel
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1021 Visits: 1176
Toreador (6/27/2012)
tim.bearne (6/27/2012)
The fact that you can get an index made to support a completely different constraint is irrelevant.


No it's not. Just because it is created for one purpose doesn't mean that it can't achieve a different purpose as well. An index created to support a unique constraint will also support the foreign key constraint, even though that's not why it was created.


But that wasn't the point of the question.

Cheers
Toreador
Toreador
Hall of Fame
Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)

Group: General Forum Members
Points: 3844 Visits: 8123
jfogel (6/27/2012)
[quote][b]
But that wasn't the point of the question.


I agree now I know the answer.
But it could have been - it was the point of the previous question in this series so why not this one too?
jfogel
jfogel
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1021 Visits: 1176
Toreador (6/27/2012)
jfogel (6/27/2012)
[quote][b]
But that wasn't the point of the question.


I agree now I know the answer.
But it could have been - it was the point of the previous question in this series so why not this one too?


Mind games!

Cheers
mtassin
mtassin
SSCertifiable
SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)

Group: General Forum Members
Points: 7296 Visits: 72521
Koen Verbeeck (6/27/2012)
vk-kirov (6/26/2012)
I can create an index by means of a unique constraint:

CREATE TABLE dbo.QotD
(KeyColumn int NOT NULL PRIMARY KEY,
RefColumn int NOT NULL,
-- More column definitions
CONSTRAINT FK_RefTab FOREIGN KEY (RefColumn)
REFERENCES dbo.RefTab(RefTabKey),
-- More constraints
CONSTRAINT UQ_RefColumn UNIQUE(RefColumn)
);


Doesn't it count as answer #2? :-)


It's possible, but I doubt a 1-1 foreign key relationship is very useful :-D

I also took answer number 2. Forgot that you cannot specify an index directly in a create table statement. D'oh!



I knew you couldn't create the index, but a 1-1 cardinality does occasionally exist, so a Uniqueness constraint specified to help the FK should be a valid way to get a Uniqueness index onto a table in the create statement.



--Mark Tassin
MCITP - SQL Server DBA
Proud member of the Anti-RBAR alliance.
For help with Performance click this link
For tips on how to post your problems
mtassin
mtassin
SSCertifiable
SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)

Group: General Forum Members
Points: 7296 Visits: 72521
Thomas Abraham (6/27/2012)
I too went for the #2 choice. I knew that the no index would be created automatically, but thought ..... same as the others. At least I have lots of company.

Thanks for the question Hugo.


I've been burned too many times by "and the rest of the create statement is syntactically correct" followed by "well you could have this or that in the rest of that statement so you're wrong".

I hate Semantics, I also hate trying to read somebody's mind when they wrote the question.



--Mark Tassin
MCITP - SQL Server DBA
Proud member of the Anti-RBAR alliance.
For help with Performance click this link
For tips on how to post your problems
mtassin
mtassin
SSCertifiable
SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)

Group: General Forum Members
Points: 7296 Visits: 72521
jfogel (6/27/2012)
Toreador (6/27/2012)
tim.bearne (6/27/2012)
The fact that you can get an index made to support a completely different constraint is irrelevant.


No it's not. Just because it is created for one purpose doesn't mean that it can't achieve a different purpose as well. An index created to support a unique constraint will also support the foreign key constraint, even though that's not why it was created.


But that wasn't the point of the question.


How do you know that for certain when you answer it? If #2 had been correct and the answer had stated that you could create a Uniqueness constraint and get a Unique Index created that would also support the foreign key, then a bunch of other folks would be crying foul.

Sorry Hugo, normally I enjoy your questions, and when I get them wrong, I still learn something. Knowing that the answer could be considered to be either #1 or #2 depending is just a little upsetting.



--Mark Tassin
MCITP - SQL Server DBA
Proud member of the Anti-RBAR alliance.
For help with Performance click this link
For tips on how to post your problems
jfogel
jfogel
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1021 Visits: 1176
If you are asking me, my point is that I answered the question based on how it was put. It didn't ask anything other than what type of index (if any) would be added based on the syntax given. All I can say is that this time I saw through a question that could have easily tripped me up. It just didn't this time. Earlier this week there was a question where I completely agreed it was confusing and suggested a "explain your answer" area would be appropriate for it. Maybe for this one too?

Cheers
John Hanrahan
John Hanrahan
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1225 Visits: 1468
I wanted desperately to pick # 2 but I couldn't figure out how to add that index before the ). YES!

I liked the question.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search