Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««1234»»

change collation on a datase Expand / Collapse
Author
Message
Posted Wednesday, March 3, 2010 1:11 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, July 7, 2010 7:37 PM
Points: 2, 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!)
Post #876319
Posted Wednesday, March 3, 2010 1:21 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, July 7, 2010 7:37 PM
Points: 2, 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
Post #876322
Posted Wednesday, March 3, 2010 10:07 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, August 12, 2014 10:06 PM
Points: 64, Visits: 294
Henrik

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

Regards

IT
Post #876540
Posted Thursday, March 4, 2010 7:03 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, August 13, 2014 8:07 AM
Points: 1,366, Visits: 989
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



Post #876811
Posted Saturday, August 7, 2010 8:48 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, April 22, 2013 10:59 AM
Points: 2, 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
Post #965554
Posted Monday, August 9, 2010 4:49 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, August 13, 2014 8:07 AM
Points: 1,366, Visits: 989
Vrosenberg,

Thank you very much for those suggestions.

Best regards,
Henrik




Post #965828
Posted Wednesday, March 16, 2011 10:05 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, June 16, 2014 9:38 AM
Points: 2,163, Visits: 2,189
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!
Post #1079081
Posted Tuesday, February 7, 2012 8:06 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, February 7, 2012 8:36 AM
Points: 1, 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..
Post #1248143
Posted Wednesday, February 8, 2012 11:28 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, August 13, 2014 8:07 AM
Points: 1,366, Visits: 989
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



Post #1249223
Posted Wednesday, February 8, 2012 12:29 PM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, June 21, 2013 9:07 PM
Points: 43, 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!
Post #1249266
« Prev Topic | Next Topic »

Add to briefcase «««1234»»

Permissions Expand / Collapse