473,383 Members | 1,868 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Changing collation types and the indexes that love them.

Hello all... I'm new here so bare with me please. I need to change collation type for a ton of tables and columns. I found a great site that showed me how to generate the sql to do this using a sql statement. This is the sql statement I'm using to generate it.

declare @fromCollation sysname,
@toCollation sysname

set @fromCollation = 'SQL_Latin1_General_CP1_CS_AS'
set @toCollation = 'SQL_Latin1_General_CP1_CI_AS'

SELECT 'ALTER TABLE ' + TABLE_NAME +
' ALTER COLUMN ' + COLUMN_NAME + ' ' + DATA_TYPE +
CASE WHEN CHARACTER_MAXIMUM_LENGTH = -1 then '(max)'
WHEN DATA_TYPE in ('text','ntext') then ''
WHEN CHARACTER_MAXIMUM_LENGTH IS NOT NULL
THEN '('+(CONVERT(VARCHAR,CHARACTER_MAXIMUM_LENGTH)+')' )
ELSE isnull(CONVERT(VARCHAR,CHARACTER_MAXIMUM_LENGTH),' ') END
+' COLLATE ' + @toCollation+ ' ' + CASE IS_NULLABLE
WHEN 'YES' THEN 'NULL'
WHEN 'No' THEN 'NOT NULL'

END
FROM INFORMATION_SCHEMA.COLUMNS
WHERE DATA_TYPE IN ('varchar' ,'char','nvarchar','nchar','text','ntext')
and COLLATION_NAME like @fromCollation

This came from the sql doctor.

On to my question. I use this sql and get a nice statement from it to change all relevant columns. The problem starts when I issue the alter table statement. I start to get errors because I have constraints that depend upon these columns. What I've read so far is that I have to remove these constraints and recreate them. This is impossible to do by hand, so I thought I'd work on writing a sql statement that'd do it for me. Using bits of code I've pulled from here I think I understand the process but I definitely don't want to delete all these constraints just to have the sql not work to recreate them. Does anyone have experience doing this type of thing? Thanks for the help!

Jerel
Apr 17 '07 #1
0 2664

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: amos | last post by:
hi i have a db with hebrew collation. i now want it to be cyrillic collation. converting the db collation - wont help. i tried exporting data to a blank DB created with cyrillic collation -...
0
by: polinaskulski | last post by:
Hi, I've got a production server with the default collation and User DBs with the different collation. Now when I create temporary tables and compare with the permanent ones we have collation...
1
by: polinaskulski | last post by:
Hi, I'm installing SQL2000 on a new cluster server. I selected a 'custom installation' and was presented with a 'Collation settings' screen. I need it to be SQL_Latin1_General_CP1_CI_AS collation...
1
by: John Jayaseelan | last post by:
Hi, The tempdb db is having different collation than the application db. I rebuilt the master db with the appropriate collation after backing up master, model, msdb, appln databases. On...
13
by: Peter | last post by:
Can anyone tell me how to change the data type of a field in a table created with a make table query? The field is a binary and must be changed to text. alternately does anyone know how to specify...
5
by: Sai | last post by:
Hi, We have around 150 databases as case sensitive, and we are planning to change it to case insensitive. Each database has around 180 tables, I have changed the collation on DB, but changing...
3
by: Nasir | last post by:
What is the best way to resolve these collation errors: My server is installed as - Latin1_General_CS_AS, but one of the important 50GB databases migrated from another server has -...
2
by: Ryan | last post by:
I have a large (ish) number of databases that various people where I work have created over the last few years. The problem is that no-one here really understands collations and a mistake made...
4
by: Danny | last post by:
Hi All, I have a varchar(255) column for storing text in english and in hebrew. It was a stupid mistake to set the data type to be varchar, because now I need to store text in german and...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.