Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Complications with SQL Server database having different collation than the server default?

We are in the process of migrating databases off an old SQL Server 2k EE server with default collation "Latin1_General_CI_AS" onto new SQL Server 2005 & 2008 servers with default collation "SQL_Latin1_General_CP1_CI_AS". There are no international characters that would require Unicode that I know of, so the two codepages are almost the same for practical purposes.

The primary SQL Server DBA is adamant that every single database (most of which are built by 3rd-party apps) must be rebuilt with the new collation before he will migrate them.

I know that ever since SQL Server 2000 it's been possible to set individual databases to have a different collation than the default. But what are the real consequences of running with mixed collations? One article from Microsoft suggests complications with the shared tempdb, for example (but can it easily be avoided?).

And, perhaps more importantly, what might we do to avoid these problems if we do need to support multiple collations on the new servers?

like image 227
ewall Avatar asked May 17 '11 13:05

ewall


People also ask

Does collation matter in SQL?

Data always follows collation constraint rules, which are configured when creating an object. When retrieving data using a T-SQL query, collation plays a fundamental role in the execution. It matters which collation is associated with a column when ordering clause is applied to that column.

What is the default SQL Server collation?

Default server-level collation is SQL_Latin1_General_CP1_CI_AS.

Which collation is best in SQL Server?

However here are the settings we typically recommend: Set the default collation to SQL_Latin1_General_CP1_CI_AS. Ensure that you have SQL Server running in Case Insensitive mode. We use NCHAR, NVARCHAR string types so all data is unicode, so no character set is specified.

Can you change the collation of a database in SQL Server?

You can change the collation of any new objects that are created in a user database by using the COLLATE clause of the ALTER DATABASE statement. This statement does not change the collation of the columns in any existing user-defined tables. These can be changed by using the COLLATE clause of ALTER TABLE.


1 Answers

The problem with different collations between server and db is as is mention before that temp tables will default be created with the server collation. That will make any comparisons on character fields between a temp table and a regular table fail. This can be avoided by the developers of the 3rd-party apps by using COLLATE database_default for character fields of temp tables.

create table #Tmp(Col1 nvarchar(50) COLLATE database_default)

I come from the "other" side. I'm not a DBA but a 3rd party software developer and I think that it is my responsibility to build my app to work in an environment where the collation is different between database and server. It is also my responsibility that my app will work with case sensitive collation.

like image 159
Mikael Eriksson Avatar answered Sep 22 '22 05:09

Mikael Eriksson