Solved

Collation Problem

Posted on 2004-09-29
9
1,495 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
 
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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

948 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now