Mike Bannon (mikeb@dataformation.co.uk) writes:
[quoted text, click to view] > As a general rule, are there performance benefits in using Numeric columns
> as indexes over Char columns? If so, are there any sources which quantify
> this?
>
> I'm thinking, for example, of where one may have a Char(6) Customer Code
> which is used as the primary key, what performance increase, if any,
> might be gained by adding a Numeric internal serial no. column as the
> primary key instead?
There are two issues here.
One is key length. If you replace your char(6) column with an integer
column, you gain two bytes per key value, and your index will be smaller,
means that for scans the index will be more effective. If you instead
use a numeric datatype, you may get the opposite effect, if you choose
a scale and precision that requires more than six bytes.
The other issue is collation. Character data is compared to under the
rules of a collation. The collation defines for instance whether lower-
case and uppercase are different letters, whether V and W sorts separately
etc. Obviously this is more complex than simple bit comparisons for an
integer value.
In the end, though, the gains you can make here may not be very significant.
For instance, if you need to keep the char(6) value, because this is a
key that is exposed to users, you may find that to retrieve the value,
you need to join to the base table to get the value. You may also find
that you need to index this column as well.
So I would suggest that firstmost look at your business requirements,
and what is best to simplify development. The gains in performance may
not be worth the extra hassle.
--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se
Books Online for SQL Server SP3 at