Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


change collation on a datase


change collation on a datase

Author
Message
mark 17451
mark 17451
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 3
Very nice Henrik. I have a need for this script as I had a client db with a different database collation to the table column collations. This as you can understand was causing problems. I have just run your script and so far it looks to have worked perfectly. I will continue testing this morning and if all ok will be running it on a live client database (after backing up of course!)
mark 17451
mark 17451
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 3
Sorry I spoke to soon ... I ended up with 88 of these messages:

ALTER TABLE ALTER COLUMN PeMobileTel failed because one or more objects access this column.

Looks like the best way forward for me will be to rebuild the database
Irwan Tjanterik
Irwan Tjanterik
Valued Member
Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)

Group: General Forum Members
Points: 66 Visits: 310
Henrik

Send me aur email, I'll send u an app I use to change collation.

Regards

IT
henrik staun poulsen
henrik staun poulsen
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1835 Visits: 1210
mark,

Is this not because you have a foreign key that you must disable first, before you can change the collation?

Then enable the FK afterwards, when the new collation is in place.

Best regards,
Henrik



Vrosenberg
Vrosenberg
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 21
I know this is an old post, but as it is also a very useful one, I will add that I needed to add a short loop at the front to turn off all check constraints, and a short one at the end to re-enable them. One does not need to list each constraint, only the tables effected

select distinct 'ALTER TABLE .[dbo].['+rtrim(P.name) +'] CHECK CONSTRAINT all'
from [INFORMATION_SCHEMA].[CHECK_CONSTRAINTS] C
join sys.sysobjects O on name=CONSTRAINT_NAME
join sys.sysobjects P on P.id=O.parent_obj

and

select distinct 'ALTER TABLE .[dbo].['+rtrim(P.name) +'] NOCHECK CONSTRAINT all'
from [INFORMATION_SCHEMA].[CHECK_CONSTRAINTS] C
join sys.sysobjects O on name=CONSTRAINT_NAME
join sys.sysobjects P on P.id=O.parent_obj


Also, since most collation changes are "TO" the instance collation, I added that at the front.

DECLARE @InstanceCollation sysname
SET @InstanceCollation = CAST( DATABASEPROPERTYEX ( 'tempdb', 'Collation' ) AS sysname)
set SET @NewCollation = @InstanceCollation
henrik staun poulsen
henrik staun poulsen
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1835 Visits: 1210
Vrosenberg,

Thank you very much for those suggestions.

Best regards,
Henrik



UMG Developer
UMG Developer
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2280 Visits: 2204
Vrosenberg (8/7/2010)
select distinct 'ALTER TABLE .[dbo].['+rtrim(P.name) +'] CHECK CONSTRAINT all'
from [INFORMATION_SCHEMA].[CHECK_CONSTRAINTS] C
join sys.sysobjects O on name=CONSTRAINT_NAME
join sys.sysobjects P on P.id=O.parent_obj


You really should have the WITH CHECK option in that to make sure that the constraints are trusted again, otherwise they aren't as valuable to the optimizer:

SELECT DISTINCT
'ALTER TABLE [dbo].[' + RTRIM(P.name) + '] WITH CHECK CHECK CONSTRAINT all'
FROM [INFORMATION_SCHEMA].[CHECK_CONSTRAINTS] C
JOIN sys.sysobjects O
ON name = CONSTRAINT_NAME
JOIN sys.sysobjects P
ON P.id = O.parent_obj



It would be nice to see these changes integrated into the script, as well as support for multiple schemas, but it is a very good start, thanks!
nemerko
nemerko
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 1
Hello All,
I'm trying to change my database collation. I read your instructions and tried your code sample too.. But after run your script on my database, there was such as errors:

"The object 'xxxx' 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."

Some of objects listed in that error report and couldn't change collation. How can i fix it? Could you help me too? Thanks in advance..
henrik staun poulsen
henrik staun poulsen
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1835 Visits: 1210
Hi nemerko,

If you have some objects with SCHEMA BINDING, such as UDFs, index views and properly other stuff too, then you need to script those out separately.

It is, as others point out, a bit of a hassel.
But it beats exporting everything to csv files, and importing it again.

Best regards,
Henrik



Oksana March
Oksana March
SSC Rookie
SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)

Group: General Forum Members
Points: 45 Visits: 317
Hi,
Could you please tell me: I have a very large database with warehouse data for many years and I have a need to enter Russian characters into one column. How can I do this??? Thank you!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search