Home All Groups Group Topic Archive Search About
Author
6 Jan 2006 11:00 PM
tshad
Is there a good reason to use int over tinyint for my look up table primary
keys?

I usually use int, but most of my look up table are 20 - 100 items max.  I
know one reason would be that you could not use a -1 as it is an unsigned
byte ( I believe).

Thanks,

Tom

Author
6 Jan 2006 11:08 PM
Dan Guzman
The proper data type selection depends mostly on the domain of values you
need to store.  A positive side affect is a smaller value range also takes
up less space.  It can be a bit of a pain to change later so it's usually
better to err on the high side.

--
Hope this helps.

Dan Guzman
SQL Server MVP

Show quote
"tshad" <tscheider***@ftsolutions.com> wrote in message
news:%23DDn4TxEGHA.648@TK2MSFTNGP14.phx.gbl...
> Is there a good reason to use int over tinyint for my look up table
> primary keys?
>
> I usually use int, but most of my look up table are 20 - 100 items max.  I
> know one reason would be that you could not use a -1 as it is an unsigned
> byte ( I believe).
>
> Thanks,
>
> Tom
>
Author
6 Jan 2006 11:41 PM
Erland Sommarskog
tshad (tscheider***@ftsolutions.com) writes:
> Is there a good reason to use int over tinyint for my look up table
> primary keys?
>
> I usually use int, but most of my look up table are 20 - 100 items max.  I
> know one reason would be that you could not use a -1 as it is an unsigned
> byte ( I believe).

I usually go for smallint in these cases. Not so much for the sign issue,
but more as a matter of routines. Sometimes you can come scaringly close to
256.

One aspect here is to make it easy to program. It's faily easy if you
know that an id in look-up tables is usually smallint, where as ids in
main entity tables are usually int. If you throw in tinyint into the
mix, programmers can more easily get confused, and use tinyint for
variables or temp-table columns that should be smallint.

--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

AddThis Social Bookmark Button