Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

Authors

Search

XML Feeds

Google Ads

« Procedures with cursorsTo BUILTIN\Admin or not to BUILTIN\Admin »
comments
Rate Post:
submit to reddit Digg!FacebookDotnetkicks

When the collation of your user database does not match the collation of TempDB, you have a potential problem. Temp tables and table variables are created in TempDB. When you do not specify the collation for string columns in your table variables and temp tables, they will inherit the default collation for TempDB. Whenever you compare and/or join to the temp table or table variable, you may get a collation conflict.

Under normal circumstances, it is best if all your collations match. This includes TempDB, Model (used for creating a new database), your user database, and all your string columns (varchar, nvarchar, char, nchar, text, ntext).

How to detect this problem:

  1. SELECT  'Warning: Collation conflict between user database and TempDB' AS Warning
  2. WHERE   DATABASEPROPERTYEX('TempDB', 'Collation') <> DATABASEPROPERTYEX(DB_NAME(), 'Collation')

How to correct it: There are several ways to correct this problem. The long term solution is to change the default collation for your database (affecting new string columns) and then change the collation for your existing columns. Alternatively, you could modify any code that creates a temp table or table variable so that it specifies a collation on your string columns. You can hard code the collation or use the default database collation.

ex:

  1. CREATE TABLE #AnyNameYouWant(Id INT, EyeColor VARCHAR(20) COLLATE Database_Default)

Level of severity: High. This is a hidden, hard to find bug, just waiting to happen.

Level of difficulty: Moderate.

About the Author

George has been developing software professionally for 19 years, first for the department of defense, and then for various other companies. In 1998, George started his software company, Orbit Software, specializing in School Bus Transportation software. His specialty is refining SQL Server queries to deliver optimal performance.
Social SitingsTwitterLTD RSS Feed
321 views
submit to reddit Digg!FacebookDotnetkicks

Comments and Feedback

1 comment

Comment from: thirster42 [Member] Email
cool. perhaps a blog/s on the different coallations and pros and cons for them?
11/19/09 @ 14:02

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)