dbTalk Databases Forums  

What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000?

comp.databases comp.databases


Discuss What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Andy
 
Posts: n/a

Default What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? - 11-30-2003 , 02:40 PM






Hi All!

We are doing new development for SQL Server 2000 and also moving from
SQL 7.0 to SQL Server 2000.

What are cons and pros for using IDENTITY property as PK in SQL SERVER
2000?
Please, share your experience in using IDENTITY as PK .


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)



Thank you in advance,
Andy

Reply With Quote
  #2  
Old   
Aaron Bertrand [MVP]
 
Posts: n/a

Default Re: What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? - 11-30-2003 , 03:11 PM






Quote:
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).

Quote:
Does SCOPE_IDENTITY makes life easier in SQL 2000?
Yes, it is more reliable than @@IDENTITY... but I don't know how it would
make life easier.

Quote:
Is there issues with DENTITY property when moving DB from one server
to another? (the same version of SQL Server)
Depends on how you define "move," and whether this is one-time or
continuous.

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/




Reply With Quote
  #3  
Old   
Daniel Morgan
 
Posts: n/a

Default Re: What are cons and pros for using IDENTITY property as PK in SQLSERVER 2000? - 11-30-2003 , 03:30 PM



Aaron Bertrand [MVP] wrote:
Quote:
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).
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.

Thanks.

--
Daniel Morgan
http://www.outreach.washington.edu/e...ad/oad_crs.asp
http://www.outreach.washington.edu/e...oa/aoa_crs.asp
damorgan@x.washington.edu
(replace 'x' with a 'u' to reply)



Reply With Quote
  #4  
Old   
Aaron Bertrand [MVP]
 
Posts: n/a

Default Re: What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? - 11-30-2003 , 03:38 PM



Quote:
What does 4 bytes have to do with it? If you had said 60 or 100 I'd
understand but why 4?
Uh, because INT (the most common datatype for IDENTITY) is 4 bytes?

Quote:
And please consider Joe Celko's voluminous comments on the subject of
artificial, or surrogate keys, when responding.
Joe's a big boy, and he can speak for himself. So can I. We don't all have
to agree on everything. This is why it's called an opinion.

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/




Reply With Quote
  #5  
Old   
Bruce Lewis
 
Posts: n/a

Default Re: What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? - 12-01-2003 , 08:29 AM



net__space (AT) hotmail (DOT) com (Andy) writes:

Quote:
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 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.
ASP.NET components that do DataBind() don't handle compound keys at all.
AFAICT, you can only set a KeyColumn parameter to a single column.

I'd personally recommend going with natural primary keys, even if
they're compound.


Reply With Quote
  #6  
Old   
Louis Davidson
 
Posts: n/a

Default Re: What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? - 12-01-2003 , 09:39 AM



Quote:
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.
This is only partially true, since what is actually missing is analysis.
Tables can have many keys, and should if there are several reasonable
natural keys, or in this case artificial keys.

Quote:
Natural primary keys also result in reports with fewer joins.
Only when you make the keys very descriptive. This kind of thing has always
made for an ugly balance of performance (smaller keys, resulting in values
that need 20 characters being condensed into 5) and usability. Joins on
very small values are very fast.
Quote:
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
What do you mean by triggers don't work as well? There are ways to create
artificial keys using triggers.

Quote:
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.
What SQL syntax has this kind of comparison? I would have figured (a,b,c)
to be a set, not three different columns.

Quote:
I'd personally recommend going with natural primary keys, even if
they're compound.
There is nothing wrong with that statement, whatsoever. Natural keys have
value, I just like the consistency of the same pattern being used for all
tables.

--
----------------------------------------------------------------------------
-----------
Louis Davidson (drsql (AT) hotmail (DOT) com)
Compass Technology Management

Pro SQL Server 2000 Database Design
http://www.apress.com/book/bookDisplay.html?bID=266

Note: Please reply to the newsgroups only unless you are
interested in consulting services. All other replies will be ignored





Reply With Quote
  #7  
Old   
Bob Badour
 
Posts: n/a

Default Re: What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? - 12-01-2003 , 11:30 AM




"Bruce Lewis" <brlspam (AT) yahoo (DOT) com> wrote

Quote:
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.
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.




Reply With Quote
  #8  
Old   
David Portas
 
Posts: n/a

Default Re: What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? - 12-01-2003 , 04:13 PM



Quote:
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.
Row-value comparisons such as this are standard in SQL92 but unfortunately
not supported by SQLServer. Oracle, I believe, does support this feature.

--
David Portas
------------
Please reply only to the newsgroup
--




Reply With Quote
  #9  
Old   
Daniel Morgan
 
Posts: n/a

Default Re: What are cons and pros for using IDENTITY property as PK in SQLSERVER 2000? - 12-01-2003 , 06:52 PM



Bob Badour wrote:

<snipped>

Quote:
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.
--
Daniel Morgan
http://www.outreach.washington.edu/e...ad/oad_crs.asp
http://www.outreach.washington.edu/e...oa/aoa_crs.asp
damorgan@x.washington.edu
(replace 'x' with a 'u' to reply)



Reply With Quote
  #10  
Old   
Bob Badour
 
Posts: n/a

Default Re: What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? - 12-01-2003 , 07:14 PM



"Daniel Morgan" <damorgan@x.washington.edu> wrote

Quote:
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.
Since when does that have any bearing on missing data in the referencing
table?




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.