Post by Martin Arvidsson, Visual Systems ABI have a customer who has a SQL 2005 server with SQL_Latin_PC1_CI_AS
collation as default.
How ever, our database is in Swedish_Finnish_CI_AS and in a couple of
sprocs we use temporary tables.
Now. Is there a way to create the temporary table and specify collation
for every field in the temp table or is the only way to declare it after
every field definition?
Create table #Temp (
My_Field Char(10) Collate Swedish_Finnish_CI_AS null,
.... etc
)
No, there isn't.
But a few comments.
First, there is an obvious mismatch here. SQL_Latin1_General_CP1_CI_AS is
a collation that is good for English, Dutch, German and a few more
languages. But it's not good for Swedish or Finnish. If your customer is
located in Sweden or Finland, your customer is likely to have installed
SQL Server incorrectly, and would benefit from making a proper
reinstallation. If your customer is located is elsewhere, you are the one
with the incorrect collation, and should you should change.
I would also like to point out here that SQL collations have their own
set of troubles, and there is all reason to avoid them. The most likely
reason why they have this collation is that when someone installed Windows,
they did not care to change the systen locale from US English, and with
US English as the system locale, the default collation is
SQL_Latin1_General_CP1_CI_AS.
Obviously, as a vendor you often have to adapt to the customer, so have
reason to reconsider how should ship your databases. While the best way
when you want to copy databases between servers is to use BACKUP/RESTORE,
I think that when you install a product, the database should be built
from scripts, either at installation, or when you build the install package.
But only in the former case, you can adapt to the customer's preferred
collation. The important thing here is that if you build the database from
scripts under source control, you know *what* you have shipped.
Finally, if your short-term solution is to add all these COLLATE clause,
don't specify the collation name, but say:
COLLATE database_default
then you don't have to change, if you build the database with, say,
Danish_Norwegian_CI_AS when your business expands westwards.
--
Erland Sommarskog, SQL Server MVP, ***@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