Re: Char or varchar for a primary key?
- From: Erland Sommarskog <esquel@xxxxxxxxxxxxx>
- Date: Mon, 28 May 2007 11:10:50 +0000 (UTC)
D. (d@xxxxx) writes:
I'm planning the structure of a SqlServer 2005 database for a new
application.
The requirement is that primary keys must be "natural"; i.e. in the table
Customers the primary key will be a max. 10 characters string (but the
string may be filled i.e. with only 5 charachters).
Should I define these primary keys as char[5] or varchar[5]?
I'm interested in your opinion in particular about performace issue,
because there will be tables with millions of records...
char(10) would make sense if key values are almost always 10 characters
long, but if the distribution varies with, say, 5 as the average varchar
would be better.
What sort of strings do you expect? If the values will be digits and upper-
case characters, you way want to consider a binary collation for the column,
at least if your default collation is a Windows collation.
--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx
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
.
- Follow-Ups:
- References:
- Char or varchar for a primary key?
- From: D.
- Char or varchar for a primary key?
- Prev by Date: Re: Char or varchar for a primary key?
- Next by Date: Re: Char or varchar for a primary key?
- Previous by thread: Re: Char or varchar for a primary key?
- Next by thread: Re: Char or varchar for a primary key?
- Index(es):
Relevant Pages
|