[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Alter columns collation

Posted on 2011-02-21
2
Medium Priority
?
493 Views
Last Modified: 2012-05-11
Hi Folks

I'm trying to write an upgrade script to fix collation problems.

When I run this:

alter table AccountingPeriodSetDesc alter column AccountingPeriodSet collate SQL_Latin1_General_CP1_CI_AS

I get this:

Server: Msg 5074, Level 16, State 8, Line 1
The index 'indAccountingPeriodSetDe00001' is dependent on column 'AccountingPeriodSetDesc'.
Server: Msg 4922, Level 16, State 1, Line 1
ALTER TABLE ALTER COLUMN AccountingPeriodSetDesc failed because one or more objects access this column.

However, when I do the change manually in SSMS, the system is clever enough to update all the tables so the DRI exists before and after, and the change is still made.

Is there a way to programmatically do this without having to recode what all the indexes and fk's etc are ? The solution must be a stable, simple system, not a great big script that might fail because the programmer forgot about a certain type of constraint ! So ideally access to the same API that SSMS uses to make these edits seemlessly - is there such as capability ? SMO or whatever ??

thanks
Paul




0
Comment
Question by:plq
2 Comments
 
LVL 27

Accepted Solution

by:
Shaun Kline earned 1000 total points
ID: 34942647
When making changes to a database object, SSMS has an option to generate the SQL script. This should include all actions that SQL Server is taking. It would be a good starting point for determining your best course of action.
0
 
LVL 26

Assisted Solution

by:tigin44
tigin44 earned 1000 total points
ID: 34943006
get the create script of the index indAccountingPeriodSetDe00001

drop index AccountingPeriodSetDesc.indAccountingPeriodSetDe00001
alter table AccountingPeriodSetDesc alter column AccountingPeriodSet collate SQL_Latin1_General_CP1_CI_AS

recrerate the index by using the script that you get
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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.
Suggested Courses

834 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