Solved

Collation Problem

Posted on 2004-09-29
9
1,527 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

615 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