![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? |
|
Does SCOPE_IDENTITY makes life easier in SQL 2000? |
|
Is there issues with DENTITY property when moving DB from one server to another? (the same version of SQL Server) |
#3
| |||
| |||
|
|
What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? Pros: - small (4 bytes) - automatic - relatively predictable (unlike GUID) - more usable (try WHERE guidColumn = {AECB...} when debugging a problem) Cons: - meaningless identifier (this can also be a good thing) - can have gaps (after delete or rollback) - can't be used in some types of replication - hotspot for insert if it is also clustered index - not portable We use it here because our natual keys are much larger than 4 bytes, and this would be inefficient (especially in indexed foreign key constraints). |
#4
| |||
| |||
|
|
What does 4 bytes have to do with it? If you had said 60 or 100 I'd understand but why 4? |
|
And please consider Joe Celko's voluminous comments on the subject of artificial, or surrogate keys, when responding. |
#5
| |||
| |||
|
|
What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? Please, share your experience in using IDENTITY as PK . |
#6
| |||||
| |||||
|
|
My experience says the theorists are right about the dangers of an artificial primary key. Many real-world database problems stem from duplicates that would never have been there with a natural primary key. |
|
Natural primary keys also result in reports with fewer joins. |
|
As for the pros of IDENTITY, if you are going to use an artificial primary key, that's the way to do it. Triggers don't work as well. A |
|
pro for artificial keys in general is that Microsoft products make compound primary keys inconvenient. Transact-SQL doesn't have tuple comparisons, e.g. (a, b, c) = (x, y, z), making joins inconvenient. |
|
I'd personally recommend going with natural primary keys, even if they're compound. |

#7
| |||
| |||
|
|
net__space (AT) hotmail (DOT) com (Andy) writes: What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? Please, share your experience in using IDENTITY as PK . My experience says the theorists are right ... .... I'd personally recommend going with natural primary keys, even if they're compound. |
#8
| |||
| |||
|
|
comparisons, e.g. (a, b, c) = (x, y, z), making joins inconvenient. What SQL syntax has this kind of comparison? I would have figured (a,b,c) to be a set, not three different columns. |
#9
| |||
| |||
|
|
The theorists disagree with you with respect to compound primary keys -- especially in SQL. Candidate keys obviously have as many attributes as they have, but forming references with compound keys causes severe problems when information may be missing. |
#10
| |||
| |||
|
|
Bob Badour wrote: snipped The theorists disagree with you with respect to compound primary keys -- especially in SQL. Candidate keys obviously have as many attributes as they have, but forming references with compound keys causes severe problems when information may be missing. I disagree. Theorists do not disagree at all with respect to compound primary keys. Primary keys, by definition, don't have missing information. If you are missing information you have something but that something is not, by definition, a primary key. |
![]() |
| Thread Tools | |
| Display Modes | |
| |