RE: Identity/Seed Values

From: David Portas (REMOVE_BEFORE_REPLYING_dportas_at_acm.org)
Date: 02/21/05


Date: Mon, 21 Feb 2005 07:31:04 -0800


> I have need for a unique number...

What you absolutely do need is a proper natural key in your data. IDENTITY
is not a substitute for this. Logically you should always be able to remove
IDENTITY and its referencing columns and replace it with another key in your
table or with another artificial key without changing its meaning. Don't
expose the IDENTITY key to users otherwise you build business processes on
something over which you don't have complete control in all cases - for
example, if you need to integrate data from multiple tables with IDENTITY
keys or in some replication scenarios.

Don't make assumptions about the sequence of IDENTITY values, its continuity
(there may be gaps) or even its uniqueness (except when it's defined with a
PK or unique constraint).

Having said all that, SQL Server doesn't change the IDENTITY value
automatically for any reason once it's assigned and you cannot change an
IDENTITY yourself except by deleting and then inserting a row (another reason
why you shouldn't tie external meaning to an arbitrary IDENTITY value).

-- 
David Portas 
SQL Server MVP 
--


Relevant Pages

  • Re: Update string too long?
    ... > And we won't question to reason for this routine as you asked... ... Pro SQL Server 2000 Database Design - ... > support the full length of the inserted data? ...
    (microsoft.public.sqlserver.programming)
  • Re: SQL 2005 Password Expiration
    ... New error codes ... Reason: Password change failed. ... password does not meet policy requirements because it is too short. ... Mike Epprecht, Microsoft SQL Server MVP ...
    (microsoft.public.sqlserver.security)
  • Re: Different results in SQL and Access
    ... This suggests a reason why you are getting different results. ... in MS-Access, with a table Linked to the SQL Server table, I get the ... This email account is my spam trap so I ...
    (microsoft.public.access.queries)
  • Re: Migrating from 97 to 2002+ / JET to MSDE
    ... On the other hand with such system now that includes emailing of data ... If you move to sql server, then it seems reasonable to have each of the ... I see no reason to migrate to sql server unless you going to use the extra ... And, as mentioned, ms-access is not going ...
    (microsoft.public.access.forms)