Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with database collation change (SQL Server 2008)

Tags:

When I tried to change the collation of my existing database (including data) from ARABIC_CS_AS to PERSIAN_100_CS_AS the following error occurs:

Alter failed for Database 'XXXX'. (Microsoft.SqlServer.Smo)

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

The object 'ItemTables' is dependent on database collation. The database collation cannot be changed if a schema-bound object depends on it. Remove the dependencies on the database collation and then retry the operation.
The object 'CK_FilteredReportColumnFilters' is dependent on database collation. The database collation cannot be changed if a schema-bound object depends on it. Remove the dependencies on the database collation and then retry the operation.
The object 'CK_FilteredReportColumnFilters_1' is dependent on database collation. The database collation cannot be changed if a schema-bound object depends on it. Remove the dependencies on the database collation and then retry the operation.
The object 'CK_FilteredReportColumnFilters_2' is dependent on database collation. The database collation cannot be changed if a schema-bound object depends on it. Remove the dependencies on the database collation and then retry the operation.
The object 'CK_Reports' is dependent on database collation. The database collation cannot be changed if a schema-bound object depends on it. Remove the dependencies on the database collation and then retry the operation.

ALTER DATABASE failed. The default collation of database 'XXXX' cannot be set to Persian_100_CS_AS. (Microsoft SQL Server, Error: 5075)

Trying to correct the errors mentioned by removing those database objects causes another error with other titles in conversion process.

Any idea ? Is there any well-defined solution to solve this problem?

like image 470
Farzin Zaker Avatar asked Sep 10 '11 10:09

Farzin Zaker


People also ask

How do I change the collation in SQL Server 2008 r2?

The database collation cannot be changed if a schema-bound object depends on it. Remove the dependencies on the database collation and then retry the operation. Msg 5072, Level 16, State 1, Line 2 ALTER DATABASE failed. The default collation of database 'land_gis' cannot be set to Persian_100_CI_AS.

How do I transfer a database from one collation to another collation in SQL Server?

The collation of the user databases is not changed. To change the collation of an existing user database or to create a new database with the appropriate collation, use the ALTER DATABASE command, and then use DTS or the bcp utility to transfer the data to the new database.

Is SQL_Latin1_General_CP1_CI_AS the same as Latin1_General_CI_AS?

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.


2 Answers

Ahh, this is one of the worst problems in SQL Server: you cannot change the collation once an object is created (this is true both for tables and databases...).

You can only save your data (don't use bcp or backup utilities, you need to place them in a csv of similar file types...), drop the database, recreate with the right collation and re-import the data into the new database...

Hope this helps.

like image 171
Cristiano Ghersi Avatar answered Nov 24 '22 23:11

Cristiano Ghersi


I have got the same issue and all objects were functions First takes full backup

script function as create. Delete these function then Run

use master
go
ALTER DATABASE xxx SET SINGLE_USER WITH ROLLBACK IMMEDIATE 
go
ALTER DATABASE xxx COLLATE yyyy
go
ALTER DATABASE xxx SET MULTI_USER
go

Recreate functions

I hope this helpful.

like image 34
Haitham Othman Avatar answered Nov 25 '22 00:11

Haitham Othman