See "ALTER DATABASE" and "Changing Collations" in SQL BOL.
ALTER DATABASE dbname COLLATE <New collation> If you want to get the best answer for your question read faq183-874 and thread183-468158. Terry L. Broadbent - DBA
SQL Server Page:
The problem(or advantage) of SQL 2000(you didn't specify which version you are using) is that your server can use one collation, you database a different collation and in your tables you can have multiple collations at a column level.
The ALTER DATABASE statement will change the entire database collation but won't change the columns. To do that you actually have to change it for each column. Here is a script I wrote a few weeks back to do a global column collation update.
Basically it uses the system tables to retrieve the table name, column name, length of the column, and only coulms whose datatype uses a collation and I have hardcoded the collation I want to change to. I also specified the current collation so that only the incorrect columns are updated.
Run the script in Query Analyser and select "Results in Text", once the script has executed you will see a list of ALTER TABLE, ALTER COLUMN commands just paste this into another query window and execute it against your database.
Make sure you know which collation you want to use first and what the existing one is.
I still think you should look into changing the database collation as well. The reason being that all stored procedure variables that use character data are saved in the syscolumns table and use the database collation and if you try a join with a variable using the db collation and a field using your new collation you might end up with a "cannot resolve collation error" because the collations are different.
Secondly when creating tables or adding columns if you don't specify the "new" collation the database collation is used by default which means you could run into more errors.
If that happens you might have to go through the whole process again or use the COLLATE function on every join that uses columns with character datatypes in every query.
Also I have tested this in SQL 2000, SQL 7 has slightly different tables so it might not work in SQL 7. Make sure you test this first in a dev instance before you apply this to your production database.
here is the sql script:
select 'ALTER TABLE ' + so.name + char(13) + 'ALTER COLUMN ' + ' ['+sc.name+'] '+ '['+st.name+']'+ '('+convert(varchar(5),sc.length)+')'+ 'COLLATE SQL_Latin1_General_CP1_CI_AS NULL'+ char(13)+ 'GO'
FROM sysobjects so, syscolumns sc, systypes st
where so.id = sc.id
and sc.xtype = st.xtype
and st.xtype in(175, 239, 99, 231, 35, 167)
and sc.collation = 'Latin1_General_CI_AS'
and so.type = 'U'
Thanx for the hint. This is the way I looked for a workaround for. So it seems to me a MS "feature"
(why on earth they make the table names case sensitive? So a "select ... from TEST" not equals "select ... from test"
But if there´s no other way we have to change all (relevant) columns
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.