Skip to content

SQL Server: How to compare Server and Database Collation

Sometimes during an SQL Server audit, I check the collation of the server and the databases but every time separately.
The goal of this blog is to give you a script to have both and compare it.

First step is to have the server collation and the code page.
The code page will help to see if the character set is the same.
For example, for us, the 1252 is Latin/Western European and the 1258 is Vietnamese.
The collation is also good to have to see the case-sensitivity, accent- sensitivity, kanatype- sensitivity & width- sensitivity.

SELECT CONVERT (varchar, SERVERPROPERTY('collation')) AS 'server_collation',collationproperty(CONVERT (varchar, SERVERPROPERTY('collation')), 'codepage') AS 'server_codepage'

The second step is to have the collation from all databases with the view sys.databases:

SELECT db.name AS datebase_name, db.collation_name AS datebase_collation, collationproperty(db.collation_name, 'codepage') AS datebase_codepage FROM sys.databases AS db

The last step is to merge these 2 queries in one and have all information about collation and code page:

SELECT CONVERT (varchar, SERVERPROPERTY('collation')) AS 'server_collation',collationproperty(CONVERT (varchar, SERVERPROPERTY('collation')), 'codepage') AS server_codepage ,
db.name AS datebase_name, db.collation_name AS datebase_collation, collationproperty(db.collation_name, 'codepage') AS datebase_codepage FROM sys.databases AS db

To finish the script, you can add a clause “where” with the difference between the 2 code pages to have only what can be a problem:

SELECT CONVERT (varchar, SERVERPROPERTY('collation')) AS 'server_collation',collationproperty(CONVERT (varchar, SERVERPROPERTY('collation')), 'codepage') AS server_codepage ,
db.name AS datebase_name, db.collation_name AS datebase_collation, collationproperty(db.collation_name, 'codepage') AS datebase_codepage FROM sys.databases AS db
where collationproperty(CONVERT (varchar, SERVERPROPERTY('collation')), 'codepage') != collationproperty(db.collation_name, 'codepage')

I hope this script can help you to see the collation and code page for the server and all databases.

Let’s work together

Ready to operate at
the next level?

Tell us about your challenge. We’ll bring the depth, the expertise, and the Swiss precision.

Stéphane Haby

Stéphane Haby

Stéphane Haby has more than 20 years of experience in Microsoft solutions, specializing in the installation, migration, best practices, and performance analysis of Microsoft SQL Server, as well as Microsoft Business Intelligence solutions (SharePoint, Office) and .NET development for the banking sector. A former Microsoft Most Valuable Professional (MVP) and early adopter of Microsoft Team System in France, he has authored several technical articles. He holds Microsoft Certified Solutions Associate (MCSA) and Expert (MCSE) for SQL Server, MCTS, MCITP for SQL Server 2008, and ITIL V3 Foundation certifications. His industry experience covers chemicals and pharma, banking, and financial services.View Author posts

182 posts since April 2011

Leave a Comment

Your email address will not be published. Required fields are marked *