Answered by:
change collation for each table in database

Question
-
Hi all,
how do I change collation for each table in database (using one command if possible) ?
- Edited by ymarkiv Friday, February 7, 2014 12:23 PM typo
Friday, February 7, 2014 12:05 PM
Answers
-
use INFORMATION_SCHEMA.COLUMNS table and look for columns with different collation. then generate code using below query
SELECT 'ALTER TABLE ' + TABLE_NAME + ' ALTER COLUMN ' + COLUMN_NAME + ' ' + DATA_TYPE + '('+ CHARACTER_MAXIMUM_LENGTH + ') ' + CASE WHEN ID_NULLABLE ='YES' THEN ' NULL ' ELSE 'NOT NULL COLLATE <your collation name here>;' FROM INFORMATION_SCHEMA.COLUMNS WHERE DATA_TYPE IN ('varchar','char','nvarchar')
then copy result onto a new window and click execute
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
- Proposed as answer by Prashanth JayaramEditor Friday, February 7, 2014 2:51 PM
- Marked as answer by pituachMVP Friday, February 14, 2014 5:37 AM
Friday, February 7, 2014 2:29 PMAnswerer -
Does this help? http://social.msdn.microsoft.com/Forums/sqlserver/en-US/e77cdd31-d6bd-46a0-afe4-77767cefd821/change-collation-per-table-level?forum=transactsql
Thanks, Andrew
My blog...- Proposed as answer by Sofiya Li Monday, February 10, 2014 7:38 AM
- Marked as answer by pituachMVP Friday, February 14, 2014 5:35 AM
Friday, February 7, 2014 12:19 PMAnswerer -
The collation is defined on column level, not on a table
See TechNet ScriptCenter: Column Collation Changer
Olaf Helper
[ Blog] [ Xing] [ MVP]- Marked as answer by pituachMVP Friday, February 14, 2014 5:37 AM
Friday, February 7, 2014 12:23 PM
All replies
-
Does this help? http://social.msdn.microsoft.com/Forums/sqlserver/en-US/e77cdd31-d6bd-46a0-afe4-77767cefd821/change-collation-per-table-level?forum=transactsql
Thanks, Andrew
My blog...- Proposed as answer by Sofiya Li Monday, February 10, 2014 7:38 AM
- Marked as answer by pituachMVP Friday, February 14, 2014 5:35 AM
Friday, February 7, 2014 12:19 PMAnswerer -
The collation is defined on column level, not on a table
See TechNet ScriptCenter: Column Collation Changer
Olaf Helper
[ Blog] [ Xing] [ MVP]- Marked as answer by pituachMVP Friday, February 14, 2014 5:37 AM
Friday, February 7, 2014 12:23 PM -
use INFORMATION_SCHEMA.COLUMNS table and look for columns with different collation. then generate code using below query
SELECT 'ALTER TABLE ' + TABLE_NAME + ' ALTER COLUMN ' + COLUMN_NAME + ' ' + DATA_TYPE + '('+ CHARACTER_MAXIMUM_LENGTH + ') ' + CASE WHEN ID_NULLABLE ='YES' THEN ' NULL ' ELSE 'NOT NULL COLLATE <your collation name here>;' FROM INFORMATION_SCHEMA.COLUMNS WHERE DATA_TYPE IN ('varchar','char','nvarchar')
then copy result onto a new window and click execute
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
- Proposed as answer by Prashanth JayaramEditor Friday, February 7, 2014 2:51 PM
- Marked as answer by pituachMVP Friday, February 14, 2014 5:37 AM
Friday, February 7, 2014 2:29 PMAnswerer