How to change an Azure SQL Database Collation
Problem
We created an Azure SQL database using the default collation that was available. Now, there is a requirement from the client to change the collation. Is it possible to change the collation of an Azure SQL database after it is created?
Solution
Technically collation change for SQL Azure DB is very much complicated process. usually it is not recommended to do so. But as a work around, you can follow these steps.
This tip assumes you already have an Azure SQL database. If you are new to Azure, try this link: https://azure.microsoft.com/en-us/free/ which will give you $200 USD credit for a month. Otherwise, logon to your Azure portal: https://portal.azure.com.
- Export the Azure SQL database to an on-premises server
- Change the database collation on the on-premises server
- Export the on-premises database
- Finally import into the Azure server with the new collation
In the next tip, we will explore how to hack the BACPAC file after exporting the Azure SQL database and re-importing the BACPAC file with the new collation.
Example the Azure SQL database collation is: SQL_Latin1_General_CP1_CI_AS.
Let us try to change the collation of the database to Latin1_General_100_CS_AS_SC.
1. You will need to export the database.
Once the process completes, you will see the final confirmation of the process completion.
Import BACPAC file to an on-premises SQL Server instance
Connect to your on-premises SQL Server instance and start the process to import the BACPAC file. Connect to your SQL instance, right click on the “Databases” option to “Import Data-tier Application”.
Once you click on “Finish”, the process of Importing the database begins.
The collation - “SQL_Latin1_General_CP1_CI_AS” is the same collation as that of the Azure SQL database. Connect to the on-premises SQL instance and run the command to change the database collation. Run this code on the on-premises SQL database to change the collation.
USE master; GO ALTER DATABASE DatabaeName COLLATE Latin1_General_100_CS_AS_SC
You can check the collation of the on-premises database to confirm that the collation has changed.
Now, again you need to export the BACPAC file and then import on Azure.
Comments
Post a Comment