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 12345»»»

Using IDENTITY as a key column Expand / Collapse
Author
Message
Posted Monday, April 19, 2010 8:10 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 10:59 AM
Points: 5,801, Visits: 8,018
Comments posted to this topic are about the item Using IDENTITY as a key column


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #906457
Posted Monday, April 19, 2010 8:19 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 5:04 PM
Points: 11,168, Visits: 10,939
First correct answer! Yay for me

I liked this question - especially the first part about IDENTITY allowing duplicates, which I am sure will surprise many people.

I am less sure about the wording in the second part of the question, "SQL Server does not have an efficient way to retrieve rows based on a known value for PersonID." because that rather depends on the number of rows in the table.

I don't think it would have been giving too much away to say something like "SQL Server cannot use an index to locate rows based on a known value for PersonID".

Paul




Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #906459
Posted Monday, April 19, 2010 8:34 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 11:20 AM
Points: 20,484, Visits: 14,140
Nice question Hugo.

I am with Paul on this one - the wording on the second part is a little iffy. It can still be answered correctly. I just had to think about it for a second.

So far, the answer rate for this question is higher than your previous questions too (50%).




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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #906464
Posted Monday, April 19, 2010 11:23 PM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 6:52 AM
Points: 667, Visits: 335
I am agree with the first statement but the second statement "SQL Server does not have an efficient way to retrieve rows based on a known value for PersonID." confusing me.

Deepak Kumar Sharma
Post #906530
Posted Monday, April 19, 2010 11:52 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 11:20 AM
Points: 20,484, Visits: 14,140
Deepak Sharma-752112 (4/19/2010)
I am agree with the first statement but the second statement "SQL Server does not have an efficient way to retrieve rows based on a known value for PersonID." confusing me.


It is in reference to the default of SQL Server creating an index on that column. For Primary key columns, an index is auto-generated - but that is not true of an identity column, unless the identity column is a part of a Primary key.




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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #906543
Posted Tuesday, April 20, 2010 12:00 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 5:04 PM
Points: 11,168, Visits: 10,939
CirquedeSQLeil (4/19/2010)
...but that is not true of an identity column, unless the identity column is a part of a Primary key.

Or a UNIQUE constraint, as the QotD explanation says




Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #906549
Posted Tuesday, April 20, 2010 12:03 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 11:20 AM
Points: 20,484, Visits: 14,140
Paul White NZ (4/20/2010)
CirquedeSQLeil (4/19/2010)
...but that is not true of an identity column, unless the identity column is a part of a Primary key.

Or a UNIQUE constraint, as the QotD explanation says


Thanks for tidying that up




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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #906553
Posted Tuesday, April 20, 2010 12:19 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 5:04 PM
Points: 11,168, Visits: 10,939
CirquedeSQLeil (4/20/2010)
Thanks for tidying that up

You can always rely on me




Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #906564
Posted Tuesday, April 20, 2010 12:39 AM


SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Thursday, March 20, 2014 12:35 AM
Points: 171, Visits: 1,764
Hang on a minute ...

"Even though the IDENTITY property is intended to be used for key columns, SQL Server will not automatically generate a constraint to enforce the uniqueness, so duplicate values (caused by the methods above) will not be banned from the table. SQL Server will also not automatically create an index to speed up access based on the IDENTITY value (though it will do so when you add the PRIMARY KEY or UNIQUE constraint to enforce uniqueness of the IDENTITY column, as it does for each PRIMARY KEY or UNIQUE constraint). "

the question asked if SQL server had an efficient way to query records, not if it would use that method automatically!


Assumption is the mother of all F***ups
Post #906569
Posted Tuesday, April 20, 2010 12:41 AM
UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Thursday, November 21, 2013 11:33 PM
Points: 1,481, Visits: 1,959
Even though i actually got this right the wording of the question aint that good. And that could be part of the reason why the correct/incorrect ration is out off wack (81% wrong at the time).

The heading said "Using IDENTITY as a key column". Key part there being "key". Now combined with the fact that the create table statement was incomplete "-- other columns);". Got me wondering if the author had a missing "primary key (PersonID)" at the end (or something similar). Or that is was implied that there would be code to create a key. Which of course would have inverted the answer.

Though this could be a result from lack of english skills on my part.

Though i must say i liked the question since i got it right
Post #906570
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse