| title | Set or Change the Database Collation | Microsoft Docs | ||
|---|---|---|---|
| ms.custom | |||
| ms.date | 10/11/2019 | ||
| ms.prod | sql | ||
| ms.reviewer | |||
| ms.technology | |||
| ms.topic | conceptual | ||
| helpviewer_keywords |
|
||
| ms.assetid | 1379605c-1242-4ac8-ab1b-e2a2b5b1f895 | ||
| author | stevestein | ||
| ms.author | sstein | ||
| monikerRange | =azuresqldb-current||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current |
[!INCLUDEappliesto-ss-asdb-xxxx-xxx-md] This topic describes how set and change the database collation in [!INCLUDEssCurrent] by using [!INCLUDEssManStudioFull] or [!INCLUDEtsql]. If no collation is specified, the server collation is used.
Important
Altering database collation is not explicitly forbidden in Azure SQL Database. However, altering database collation reqiures exclusive lock on database and other user or background processes (for example background that is taking the backups) might hold the database locks and prevent collation change. ALTER DATABASE COLLATE statement on Azure SQL Database will fail if it is executed while the background processes are accessing database. You would need to retry the statement if you are getting lock timeout error.
Note
Collation cannot be changed using [!INCLUDEssManStudioFull] after database has been created on [!INCLUDEssSDSfull]. It can be changed only through [!INCLUDEtsql].
In This Topic
-
Before you begin:
-
To set or change the database collation, using:
-
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 cannot 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 is not supported by Windows, the [!INCLUDEssDE] displays an error.
-
Collation cannot be changed using [!INCLUDEssManStudioFull] after database has been created on [!INCLUDEssSDSfull]. It can be changed only through [!INCLUDEtsql].
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 the following:
-
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.
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.
-
In Object Explorer, connect to an instance of the [!INCLUDEssDEnoversion], expand that instance, and then expand Databases.
-
If you are creating a new database, right-click Databases and then click New Database. If you do not want the default collation, click 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 click Properties. Click the Options page, and select a collation from the Collation drop-down list.
-
After you are finished, click OK.
-
Connect to the [!INCLUDEssDE].
-
From the Standard bar, click New Query.
-
Copy and paste the following example into the query window and click Execute. This example shows how to use the COLLATE clause to specify a collation name. The example creates the database
MyOptionsTestthat uses theLatin1_General_100_CS_AS_SCcollation. After you create the database, execute theSELECTstatement to verify the setting.
USE master;
GO
IF DB_ID (N'MyOptionsTest') IS NOT NULL
DROP DATABASE MyOptionsTest;
GO
CREATE DATABASE MyOptionsTest
COLLATE Latin1_General_100_CS_AS_SC;
GO
--Verify the collation setting.
SELECT name, collation_name
FROM sys.databases
WHERE name = N'MyOptionsTest';
GO -
Connect to the [!INCLUDEssDE].
-
From the Standard bar, click New Query.
-
Copy and paste the following example into the query window and click Execute. This example shows how to use the COLLATE clause in an ALTER DATABASE statement to change the collation name. Execute the
SELECTstatement to verify the change.
USE master;
GO
ALTER DATABASE MyOptionsTest
COLLATE French_CI_AS ;
GO
--Verify the collation setting.
SELECT name, collation_name
FROM sys.databases
WHERE name = N'MyOptionsTest';
GO 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)