Razvan Socol
3/16/2007 7:24:00 AM
On Mar 16, 9:07 am, "Lim Siew Yin" <limsyn.nos...@gmail.com> wrote:
> > Naively adding IDENTITY columns as an "instant primary key" has the
> > potential to cause a lot of trouble for you. Convenient they are NOT.
> > It's far more important that you normalize your data model first. Do
>
> Don't worry... i already have the data model ready. What i was struggling
> was whether to use alphanumeric for more easy-to-understand data or bigint
> identity for my primary keys.
> (eg. CustomerID .... bigint identity or alphanumeric? Bigint identity is
> convenient to implement whereas I can make more meaningful coding by using
> alphanumeric ... 100102 vs AKL11012 ... something along the line)
> I usually use the alphanumeric method.. which ended up me needing a table to
> store the running numbers and a stored proc like gimmeNewCustomerID
> So basically, before i take the plunge, i wanted to know what is the norm
> out there and if there are pitfalls ... what are they.
>
> Err.. lastly, i don't really understand the danger you tried to describe
> (sorry.. i am really really bad with technical terms...)
> Can you explain further?> you have alternate keys on every table for which IDENTITY is the
> > surrogate key? If not, then you already have problems.
>
> Alternate keys as in Secondary keys? or just key fields? (fields to be
> indexed but are not indicated as keys or constraints)
> Surrogate key? as in Secondary keys? Foreign keys?
>
> [...]
Considering your above example, before worrying what data type you
should use for the CustomerID column (which is a surrogate key,
because it's generated by the database), you should think if you
already have a unique key in the Customers table (like CustomerName or
EmailAddress) which is entered by the user. If you don't, then the
user may enter the "Foobar Company Inc" customer twice (and the system
will generate the CustomerID-s FBR001 and FBR002, for example, without
complaining that the user is entering duplicate data). Unwanted
duplicates in a table can be a very serious problem, as they can
denaturate the results of a lot of reports (besides allowing
contradictory values for other columns).
Razvan