Updating database collation
Had some fun trying to update a database collation. I didn’t have to worry about the data i just needed to the collation changed so that some cross database scripts would still function in order to carry out some testing.
Here is a nice little script I found that will generate scripts to change the collation on the required columns. Some of it fails if primary keys or indexes are against the columns but this will do 90%.
CAST(o.table_name + ‘ -> ‘ + c.name AS VARCHAR(60))
, ‘ALTER TABLE ‘ + o.table_name +
‘ ALTER COLUMN [‘ + c.name + ‘] ‘ +
UPPER(t.name) + ‘(‘ +
WHEN t.name IN (‘nchar’, ‘nvarchar’) AND c.max_length != -1 THEN CAST(c.max_length / 2 AS NVARCHAR(10))
WHEN t.name IN (‘nchar’, ‘nvarchar’) AND c.max_length = -1 THEN ‘MAX’
ELSE CAST(c.max_length AS NVARCHAR(10))
END + ‘) COLLATE ‘ + @collate +
CASE WHEN c.is_nullable = 1
THEN ‘ NULL’
ELSE ‘ NOT NULL’
FROM sys.columns c WITH (NOWAIT)
table_name = ‘[‘ + s.name + ‘].[‘ + o.name + ‘]‘
FROM sys.objects o WITH (NOWAIT)
JOIN sys.schemas s WITH (NOWAIT) ON o.[schema_id] = s.[schema_id]
WHERE o.[type] = ‘U’
) o ON c.[object_id] = o.[object_id]
JOIN sys.types t WITH (NOWAIT) ON c.system_type_id = t.system_type_id AND c.user_type_id = t.user_type_id
WHERE t.name IN (‘char’, ‘varchar’, ‘text’, ‘nvarchar’, ‘ntext’, ‘nchar’)
–AND c.collation_name != @collate
Paul is a an expert SharePoint and Project Server developer and is responsible for designing and implementing custom solutions on client systems using the latest SharePoint and .NET technologies.
Paul has extensive experience with SharePoint systems across all sizes of implementation, ranging from small to large farms and has an excellent understanding of all the elements of SharePoint.