Re: Char or varchar for a primary key?



D. (d@xxxxx) writes:
How do I set binary collation on a single column?

With the COLLATE clause:


CREATE TABLE mytable (
col char(10) COLLATE Latin1_General_BIN2 NOT NULL,
...

Do you think that this will improve performance on lookups?

Yes, since comparison is a straight byte-comparison you gain some cycles,
particularly if your default collation is a Windows collation. It's
diffiuclt to say exactly how much you will gain, because there is a lot
of if depends. For a simple lookup, it's may be only 5-10%. For an
operation as "col LIKE '%str%' it may be drastic as a factor of seven.

If your default collation is an SQL collation (one there the name starts
with SQL), the gain is likely to be so small, that it's not worth the
pain. Note that this only applies if you use char/varchar. For
nchar/nvarchar there is no difference between SQL and Windows collations.

Do you think that having a single column with a different collation will
not decrease performance?

It will not, but there will be more hassle with programming. And it
would not be the only column with that collation, if there are other
tables with foreign keys to this table.

--
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: Find all chars in table that are ASCII code 128 and Greater
    ... I couldnt find any good documentation on it. ... The COLLATE clause is documented in Books Online. ... collation, because the range A-Z expands to AbBC ...zZ. ... keep in mind that SQL Server not support storing UTF-8 data. ...
    (comp.databases.ms-sqlserver)
  • 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: Advice on Create a SQL Server
    ... Use the default collation. ... domain, and running on a windows domain account, it is better to run under ... Windows Authentication mode. ... to SQL Server using a username/password. ...
    (microsoft.public.sqlserver.setup)
  • RE: Advice on Create a SQL Server
    ... Use the default collation. ... Mode" - it depends on how you will be connecting to your database. ... domain, and running on a windows domain account, it is better to run under ... to SQL Server using a username/password. ...
    (microsoft.public.sqlserver.setup)
  • Re: Installing SQL_Latin1_General_CP1_CI_AS collation order??
    ... Tibor Karaszi, SQL Server MVP ... "Ward Horsfall" wrote in message ... >> rebuildm.exe) interfaces and a collation designator, ...
    (microsoft.public.sqlserver.setup)