SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Changing table collation?


Changing table collation?

Author
Message
Mark F-428640
Mark F-428640
Old Hand
Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)

Group: General Forum Members
Points: 348 Visits: 557
I have been searching for the syntax to change the collation on a table that I am inserting into another DB for example:

SELECT * INTO dbCurrent..My_new_table FROM dbOld..Old_collated_table

So now I want the My_new_table to be collated to SQL_Latin1_General_CP1_CI_AS what is the correct syntax to make this change.
noeld
noeld
SSCrazy Eights
SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)

Group: General Forum Members
Points: 9674 Visits: 2048
You can use COLLATE clause but it will have to be applied to each character column.

By the way "tables" do not have collation, columns do!


* Noel
Mark F-428640
Mark F-428640
Old Hand
Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)

Group: General Forum Members
Points: 348 Visits: 557
So let me get a little more specific here is my code:

update A
set A.f1= B.f1
from db1..table1 A
join db2..table2 B
on A.My_field= B.My_field


The offending field is B.My_field which appears to be causing the collation error (failed with the following error: "Cannot resolve the collation conflict between "Latin1_General_CI_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.)

How do I change the collation on the fly -- please post code?
noeld
noeld
SSCrazy Eights
SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)

Group: General Forum Members
Points: 9674 Visits: 2048
Mark Fyffe (12/30/2008)
So let me get a little more specific here is my code:

update A
set A.f1= B.f1
from db1..table1 A
join db2..table2 B
on A.My_field= B.My_field


The offending field is B.My_field which appears to be causing the collation error (failed with the following error: "Cannot resolve the collation conflict between "Latin1_General_CI_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.)

How do I change the collation on the fly -- please post code?



update A
set A.f1= B.f1
from db1..table1 A
join db2..table2 B
on A.My_field= B.My_field COLLATE SQL_Latin1_General_CP1_CI_AS



Note that "f1" could also need the "fix" if it is a character column with different collation attributes.

Hope it helps,


* Noel
Mark F-428640
Mark F-428640
Old Hand
Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)

Group: General Forum Members
Points: 348 Visits: 557
Great help -- thanks
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