Solved

Collation Problem

Posted on 2004-09-29
9
1,505 Views
Last Modified: 2011-10-03
This is a strange one.

I have a SQL2000 server that has been set up for collation SQL_Latin1_General_Pref_CP850_CI_AS

However when i add a new table, the collation for varchar fileds is created as SQL_Latin1_General_CP1_CI_AS

What the hell is going on?

All the tables i have moved from my otherserver that were cp850 are now also cp1! How can i get the default collation to work again?

Thanks

Simon
0
Comment
Question by:CaptainRantflaps
  • 5
  • 4
9 Comments
 
LVL 12

Accepted Solution

by:
patrikt earned 250 total points
ID: 12178108
In SQL 2000 is server collation used only for compatibility and as default, but default for new databases not tables.
Table colleation default is collation of its database.

Look on database collation.

Patrik
0
 
LVL 5

Author Comment

by:CaptainRantflaps
ID: 12178185
Ok, as a final note, dont worry patrik, the points are already yours, but is there any easy wasy to alter every col in every table already created to the new collation?

0
 
LVL 12

Expert Comment

by:patrikt
ID: 12178205
Not easy. There is way how to list columns in existing tables so there must be way how to construst ALTER statements.

Give me a minute and I'll try to find.
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 12

Expert Comment

by:patrikt
ID: 12178275
Not tested but you can try this:

-----

declare @table varchar(100),@coll varchar(100),@sql varchar(1000)

declare tab  cursor for
select *,sysobjects.name as tbl, syscolumns.name as coll from syscolumns
inner join  sysobjects on sysobjects.id=syscolumns.id
where collation is not null
and sysobjects.xtype='U'

OPEN tab

FETCH NEXT FROM tab INTO @table, @coll

WHILE @@fetch_status=0
BEGIN
      set @sql='ALTER TABLE '+@table+' ALTER COLUMN '+@coll+'COLLATE Latin1_General_CI_AS'
      EXECUTE @sql
      SELECT @table,@coll,@sql
      FETCH NEXT FROM tab INTO @table, @coll
END

close tab
DEALLOCATE  tab
0
 
LVL 5

Author Comment

by:CaptainRantflaps
ID: 12178291
Thaks Patrik, My network admin set the server up last week when I was off, and then transfered all 200+ tables over!

DOH!

Your help is must appreciated, i will give it a spin.
0
 
LVL 12

Expert Comment

by:patrikt
ID: 12178300
Let me know how it worked.
For 200+ tables you have to check statements produced by that procedure first and then run it.
0
 
LVL 5

Author Comment

by:CaptainRantflaps
ID: 12178541
Hi Patrik,

Still having a little trouble,

I amended the statement to remove the * from select * etc, and added a space in the alter statement - the whole thing now reads (see below) however there is a syntax error in the statement created near the collate statement. The statement produced is


ALTER TABLE table1 ALTER COLUMN test1 COLLATE Latin1_General_CI_AS

however looking it up, i need to include the datatype of the column ie


ALTER TABLE table1 ALTER COLUMN test1 char(10) COLLATE Latin1_General_CI_AS

Is there anyway you know of to get this from the system tables, because the tables all have differing datatypes and lengths etc.

Thanks again,

Simon




----------------------------------------------------------------------------------------------

declare @table varchar(100),@coll varchar(100),@sql varchar(1000)

declare tab  cursor for
select sysobjects.name as tbl, syscolumns.name as coll from syscolumns
inner join  sysobjects on sysobjects.id=syscolumns.id
where collation is not null
and sysobjects.xtype='U'

OPEN tab

FETCH NEXT FROM tab INTO @table, @coll

WHILE @@fetch_status=0
BEGIN
     set @sql='ALTER TABLE '+@table+' ALTER COLUMN '+@coll+' COLLATE Latin1_General_CI_AS'
     EXECUTE @sql
     SELECT @table,@coll,@sql
     FETCH NEXT FROM tab INTO @table, @coll
END

close tab
DEALLOCATE  tab

----------------------------------------------------------------------------------------------

0
 
LVL 12

Expert Comment

by:patrikt
ID: 12178630
Ok. Whats about this:

declare @table varchar(100),@coll varchar(100),@sql varchar(1000),@type varchar(100),@isnull varchar(100)


declare tab  cursor for
select
table_name, column_name,data_type+'('+cast(character_maximum_length as varchar)+')',
case IS_NULLABLE WHEN 'No' THEN  'NOT NULL' ELSE '' END
from INFORMATION_SCHEMA.COLUMNS
where collation_name is not null
and table_name not like 'sys%'

OPEN tab

FETCH NEXT FROM tab INTO @table, @coll, @type,@isnull

WHILE @@fetch_status=0
BEGIN
      set @sql='ALTER TABLE '+@table+' ALTER COLUMN '+@coll+' '+@type+' COLLATE Latin1_General_CI_AS '+@isnull
      --EXECUTE @sql
      SELECT @sql
      FETCH NEXT FROM tab INTO @table, @coll, @type,@isnull
END

close tab
DEALLOCATE  tab

0
 
LVL 5

Author Comment

by:CaptainRantflaps
ID: 12178648
Thanks brilliant works perfectly , thanks once again for your help.

Simon
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question