You are here: Re: Char or varchar for a primary key? « MsSQL Server « IT news, forums, messages
Re: Char or varchar for a primary key?

Posted by Erland Sommarskog on 05/28/07 11:10

D. (d@d.com) 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@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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация