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

« To BUILTIN\Admin or not to BUILTIN\AdminDon't use text datatype for SQL 2005 and up »
comments
Rate Post:
submit to reddit Digg!FacebookDotnetkicks

Collations control how strings are sorted and compared. Sorting is not usually a problem because it does not cause collation conflicts. It may not sort the way you want it to, but it won't cause errors. The real problem here is when you compare data. Comparisons can occur several different ways. This can be a simple comparison in a where clause, or a comparison in a join condition. By having columns in your database that do not match the default collation of the database, you have a problem just waiting to happen.

When you add a new column to an existing table or create a new table with string column(s), and you do NOT specify the collation, it will use the default collation of the database. If you then write queries that join with existing columns (that has a different collation) you will get collation conflict errors.

Just to be clear here, I am NOT suggesting that every string column should have a collation that matches the default collation for the database. Instead, I am suggesting that when it is different, there should be a good reason for it. There are many successful databases out there where the developers never give any thought to the collation. In this circumstance, it's best for the collations for each string column match the default collation for the database.

How to detect this problem:

  1. SELECT  C.Table_Name, Column_Name
  2. FROM    Information_Schema.Columns C
  3.         INNER Join Information_Schema.Tables T
  4.           ON C.Table_Name = T.Table_Name
  5. WHERE   T.Table_Type = 'Base Table'
  6.         And Collation_Name <> DATABASEPROPERTYEX(DB_NAME(), 'Collation')
  7.         And COLUMNPROPERTY(OBJECT_ID(C.Table_Name), Column_Name, 'IsComputed') = 0
  8. ORDER BY C.Table_Name, C.Column_Name

How to correct it: To correct this problem, you can modify the collation for your existing string columns.

Level of severity: High
Level of difficulty: Easy

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
406 views
submit to reddit Digg!FacebookDotnetkicks

Comments and Feedback

1 comment

Comment from: onpnt [Member] Email
commonly overlooked for case match criteria also. Great post!
11/18/09 @ 08:48

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.)