Re: Char or varchar for a primary key?



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
.



Relevant Pages

  • Re: Default charset in sqlserver 2000? / jtds
    ... > The columns share this collation. ... points are control characters to 8859-1. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Multiple Primary Keys
    ... >When I have two primary keys on my table, ... In the table datasheet?? ... >and the other is a date (2nd field, 10 characters). ... I'm not at all sure what it is you're trying to "adjust". ...
    (microsoft.public.access.gettingstarted)
  • Re: Stored proc with version number ?
    ... in addition to letter characters from other languages. ... Certain symbols at the beginning of an identifier have special meaning ... in SQL Server. ... I choose> the existing stored proc uspTableSave and right click Properties. ...
    (microsoft.public.sqlserver.programming)
  • Re: Can you use osql in DTS?
    ... each one of these queries has in it the same first 18 characters (or ... it from Query #3. ... > Columnist, SQL Server Professional ...
    (microsoft.public.sqlserver.dts)
  • Re: Can you use osql in DTS?
    ... each one of these queries has in it the same first 18 characters (or ... it from Query #3. ... > Columnist, SQL Server Professional ...
    (microsoft.public.sqlserver.programming)