Solved

Collation Problem

Posted on 2004-09-29
9
1,520 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

728 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