Set or change the database collation - SQL Server (2024)

  • Article

Applies to: Set or change the database collation - SQL Server (1) SQL Server Set or change the database collation - SQL Server (2) Azure SQL Managed Instance

This article describes how to set or change the database collation by using SQL Server Management Studio (SSMS) or Transact-SQL. If no collation is specified, the server collation is used.

Limitations and restrictions

  • Windows Unicode-only collations can only be used with the COLLATE clause to apply collations to the nchar, nvarchar, and ntext data types on column level and expression-level data. They can't be used with the COLLATE clause to change the collation of a database or server instance.

  • If the specified collation or the collation used by the referenced object uses a code page that isn't supported by Windows, the Database Engine displays an error.

  • Server-level collation in Azure SQL Managed Instance can be specified when the instance is created and cannot be changed later. Learn more in Set or change the server collation.

Important

The ALTER DATABASE COLLATE statement is not supported on Azure SQL Database. Specify database collation and catalog collation at the time of CREATE DATABASE.

Recommendations

You can find the supported collation names in Windows Collation Name (Transact-SQL) and SQL Server Collation Name (Transact-SQL); or you can use the sys.fn_helpcollations (Transact-SQL) system function.

When you change the database collation, you change:

  • Any char, varchar, text, nchar, nvarchar, or ntext columns in system tables are changed to the new collation.

  • All existing char, varchar, text, nchar, nvarchar, or ntext parameters and scalar return values for stored procedures and user-defined functions are changed to the new collation.

  • The char, varchar, text, nchar, nvarchar, or ntext system data types, and all user-defined data types based on these system data types, are changed to the new default collation.

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.

Important

Changing the collation of a database or individual columns does not modify the underlying data already stored in existing tables. Unless your application explicitly handles data conversion and comparison between different collations, it is recommended that you transition existing data in the database to the new collation. This removes the risk that applications may incorrectly modify data, resulting in possible wrong results or silent data loss.

When a database collation is changed, only new tables will inherit the new database collation by default. There are several alternatives to convert existing data to the new collation:

  • Convert data in-place. To convert the collation for a column in an existing table, see Set or Change the Column Collation. This operation is easy to implement, but may become a blocking issue for large tables and busy applications. See the following example for an in-place conversion of the MyString column to a new collation:

    ALTER TABLE dbo.MyTable ALTER COLUMN MyString VARCHAR(50) COLLATE Latin1_General_100_CI_AI_SC_UTF8;
  • Copy data to new tables that use the new collation, and replace original tables in the same database. Create a new table in the current database that will inherit the database collation, copy the data between the old table and the new table, drop the original table, and rename the new table to the name of the original table. This is a faster operation than an in-place conversion, but may become a challenge when handling complex schemas with dependencies such as Foreign Key constraints, Primary Key constraints, and Triggers. It would also require a final data synchronization between the original and the new table before the final cut-off, if data continues to be changed by applications. See the following example for a "copy and replace" conversion of the MyString column to a new collation:

    CREATE TABLE dbo.MyTable2 (MyString VARCHAR(50) COLLATE Latin1_General_100_CI_AI_SC_UTF8); INSERT INTO dbo.MyTable2 SELECT * FROM dbo.MyTable; DROP TABLE dbo.MyTable; EXEC sp_rename 'dbo.MyTable2', 'dbo.MyTable';
  • Copy data to a new database that uses the new collation, and replace the original database. Create a new database using the new collation, and transfer the data from the original database via tools like Integration Services or the Import/Export Wizard in SQL Server Management Studio. This is a simpler approach for complex schemas. It would also require a final data synchronization between the original and the new databases before the final cut-off, if data continues to be changed by applications.

Permissions

To create a new database, requires CREATE DATABASE permission in the master database, or requires CREATE ANY DATABASE, or ALTER ANY DATABASE permission.

To change the collation of an existing database, requires ALTER permission on the database.

Set or change the database collation using SSMS

  1. In Object Explorer, connect to an instance of the SQL Server Database Engine, expand that instance, and then expand Databases.

  2. If you are creating a new database, right-click Databases and then select New Database. If you don't want the default collation, select the Options page, and select a collation from the Collation drop-down list.

    Alternatively, if the database already exists, right-click the database that you want and select Properties. Select the Options page, and select a collation from the Collation drop-down list.

  3. After you are finished, select OK.

Set the database collation using Transact-SQL

  1. Connect to the Database Engine.

  2. From the Standard bar, select New Query.

  3. Copy and paste the following example into the query window and select Execute. This example shows how to use the COLLATE clause in CREATE DATABASE to specify a collation name. The example creates the database MyOptionsTest that uses the Latin1_General_100_CS_AS_SC collation. After you create the database, execute the SELECT statement to verify the setting.

USE master; GOIF DB_ID (N'MyOptionsTest') IS NOT NULL DROP DATABASE MyOptionsTest; GOCREATE DATABASE MyOptionsTest COLLATE Latin1_General_100_CS_AS_SC; GO SELECT name, collation_name FROM sys.databases WHERE name = N'MyOptionsTest'; GO 

Change the database collation using Transact-SQL

  1. Connect to the Database Engine.

  2. From the Standard bar, select New Query.

  3. Copy and paste the following example into the query window and select Execute. This example shows how to use the COLLATE clause in an ALTER DATABASE statement to change the collation name. Execute the SELECT statement to verify the change.

USE master; GOALTER DATABASE MyOptionsTest COLLATE French_CI_AS ; GO SELECT name, collation_name FROM sys.databases WHERE name = N'MyOptionsTest'; GO 

Next steps

Learn more about collation:

  • Collation and Unicode Support
  • sys.fn_helpcollations (Transact-SQL)
  • sys.databases (Transact-SQL)
  • SQL Server Collation Name (Transact-SQL)
  • Windows Collation Name (Transact-SQL)
  • COLLATE (Transact-SQL)
  • Collation Precedence (Transact-SQL)
  • CREATE TABLE (Transact-SQL)
  • CREATE DATABASE (SQL Server Transact-SQL)
  • ALTER TABLE (Transact-SQL)
  • ALTER DATABASE (Transact-SQL)
Set or change the database collation - SQL Server (2024)

FAQs

Set or change the database collation - 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.

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

Change the server collation in SQL Server

Instead of changing the default collation of an instance of SQL Server, you can specify a default collation for each new database you create via the COLLATE clause of the CREATE DATABASE and ALTER DATABASE statements.

What does SQL_Latin1_General_CP1_CI_AS mean? ›

The SQL_Latin1_General_CP1_CI_AS collation is a SQL collation and the rules around sorting data for unicode and non-unicode data are different. The Latin1_General_CI_AS collation is a Windows collation and the rules around sorting unicode and non-unicode data are the same.

What database collation should I use? ›

If you are unsure which character set or collation to use, the MySQL default utf8mb4 character set and its default utf8mb4_0900_ai_ci collation are usually good choices. They support all Unicode characters and provide case-insensitive and accent-insensitive comparisons.

What is the default collation in SQL Server? ›

Per Microsoft, if your Windows locale is any English speaking country (except the US) your default SQL server collation during setup is: Latin1_General_CI_AS , but in the US it is still SQL_Latin1_General_CP1_CI_AS for backward compatibility.

How to check db collation in SQL Server? ›

Expand Databases, expand the database and then expand Tables. Expand the table that contains the column and then expand Columns. Right-click the column and select Properties. If the collation property is empty, the column is not a character data type.

What is a database collation? ›

In a database, a collation is a set of rules that determine how data is sorted and compared, usually applied to how text data is sorted in different languages for the purpose of indexing text data and for making comparisons between text values. Different languages have different character sets and ordering.

How to remove COLLATE in SQL Server? ›

The way to remove the collate statements is,
  1. Using the Bulk Editor, one can easily do a mass deletion of all collations values for the attributes.
  2. However, you also need to remove it from the database. Right-click on Databases in the Model Explorer and remove any text from the Collation Column for each database.
Mar 28, 2018

What is COLLATE Latin1_General_BIN in SQL Server? ›

Common collation names either end in _BIN or _CI_AS such as Latin1_General_BIN or SQL_Latin1_General_CI_AS. The _BIN means that this is a binary sort order where strings will be sorted using a computer binary order, the result is that A-Z are before a-z and things like accented characters will be at the end.

Does collation matter in SQL? ›

Collations in SQL Server provide sorting rules, case, and accent sensitivity properties for your data. Collations that are used with character data types, such as char and varchar, dictate the code page and corresponding characters that can be represented for that data type.

What is the difference between character set and collation in SQL Server? ›

A character set is a set of symbols and encodings. A collation is a set of rules for comparing characters in a character set.

What is the difference between data collection and collation? ›

First, you collect the data from the people you have surveyed: you gather it in one place. Second, you collate the data: you arrange it in order and begin to categorise it. The difference is that collection is a set of items or amount of material procured or gathered together while collation is bringing together.

Can I change the collation of a database? ›

Set or change the database collation using SSMS

Alternatively, if the database already exists, right-click the database that you want and select Properties. Select the Options page, and select a collation from the Collation drop-down list. After you are finished, select OK.

Can I change SQL Server collation after installation? ›

Unfortunately, the only good way to change the collation after the DB is installed is to rebuild the server from scratch or rebuild your system databases. You can't simply run an ALTER DATABASE statement to change it either.

What is the difference between SQL_Latin1_General_CP1_CI_AS and Latin1_General_CI_AS? ›

Latin1_General_CI_AS is a Windows collation and can use an index when comparing unicode and non unicode data, where SQL_Latin1_General_CP1_CI_AS is a SQL collation and cannot do this.

How to change collation in SQL Server 2008 R2 after installation? ›

Steps for changing collation

Take backup of all the databases & logins exists in the server for safer side. Insert SQL Server 2008 CD DVD into drive. Below is the syntax for changing the collation at serverlevel, please note that this will rebuild all the system databases in that instance/.

How do I change the collation of an existing database in MySQL? ›

Select the database you wish to manage from the drop-down menu on the left. Click on Operations in the top menu of your phpMyAdmin. At the bottom of the page, you will see the collation option. Select a collation from the drop-down menu and click on Go.

How to use COLLATE database_default? ›

In a T-SQL CREATE TABLE statement, you can include the COLLATE DATABASE_DEFAULT to specify that a column or table should use the database's default collation. In Babelfish, you should either remove the COLLATE DATABASE_DEFAULT clause, or specify the collation name.

What is Latin1_General_BIN? ›

Common collation names either end in _BIN or _CI_AS such as Latin1_General_BIN or SQL_Latin1_General_CI_AS. The _BIN means that this is a binary sort order where strings will be sorted using a computer binary order, the result is that A-Z are before a-z and things like accented characters will be at the end.

Top Articles
Colonial Pipeline hack explained: Everything you need to know
Most Demanded Products in India: 25 Trending Ideas for September 2024
Television Archive News Search Service
Junk Cars For Sale Craigslist
Mr Tire Prince Frederick Md 20678
Find All Subdomains
Videos De Mexicanas Calientes
Best Cheap Action Camera
Campaign Homecoming Queen Posters
Günstige Angebote online shoppen - QVC.de
Athens Bucket List: 20 Best Things to Do in Athens, Greece
Turning the System On or Off
8 Ways to Make a Friend Feel Special on Valentine's Day
Accuradio Unblocked
Lax Arrivals Volaris
This Modern World Daily Kos
Scenes from Paradise: Where to Visit Filming Locations Around the World - Paradise
Aldi Sign In Careers
Gentle Dental Northpointe
Epguides Strange New Worlds
Accident On The 210 Freeway Today
Apple Original Films and Skydance Animation’s highly anticipated “Luck” to premiere globally on Apple TV+ on Friday, August 5
Ahn Waterworks Urgent Care
Panolian Batesville Ms Obituaries 2022
Sodium azide 1% in aqueous solution
Rochester Ny Missed Connections
Vera Bradley Factory Outlet Sunbury Products
Farm Equipment Innovations
Phoenixdabarbie
Obituaries, 2001 | El Paso County, TXGenWeb
Warn Notice Va
La Qua Brothers Funeral Home
Kristen Hanby Sister Name
2430 Research Parkway
Colorado Parks And Wildlife Reissue List
The Land Book 9 Release Date 2023
Shuaiby Kill Twitter
Anguilla Forum Tripadvisor
Restored Republic June 6 2023
Cnp Tx Venmo
If You're Getting Your Nails Done, You Absolutely Need to Tip—Here's How Much
Citizens Bank Park - Clio
Ssc South Carolina
Kjccc Sports
Wolf Of Wallstreet 123 Movies
Minterns German Shepherds
Zits Comic Arcamax
Pronósticos Gulfstream Park Nicoletti
Taterz Salad
Cool Math Games Bucketball
Latest Posts
Article information

Author: Gov. Deandrea McKenzie

Last Updated:

Views: 5760

Rating: 4.6 / 5 (46 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Gov. Deandrea McKenzie

Birthday: 2001-01-17

Address: Suite 769 2454 Marsha Coves, Debbieton, MS 95002

Phone: +813077629322

Job: Real-Estate Executive

Hobby: Archery, Metal detecting, Kitesurfing, Genealogy, Kitesurfing, Calligraphy, Roller skating

Introduction: My name is Gov. Deandrea McKenzie, I am a spotless, clean, glamorous, sparkling, adventurous, nice, brainy person who loves writing and wants to share my knowledge and understanding with you.