Lowell, Thanks for this, you saved me a bunch of work this week. I had a couple vendor installed databases that had wrong collation. I was able to use your script to fix them. A few issues I ran across testing your script:
1)Doubling of nvarchar size - I see you were already notifed on this so won't go into detail
2)Foreign Key creation - I had several foreign keys that were set up with ON DELETE CASCADE. This was lost on your rebuild of the foreign key constraint. I add the following code to the end of the select that builds the statement to fix:
WHEN conz.delete_referential_action = 1
THEN ' ON DELETE CASCADE'
3)Index Creation - I had issues with unique indexes that were built using a create index statement vs a unique constraint. Also had issues with clustered indexes that were not set up as a primary key. Your create index build would only create non-unique, nonclustered indexes. In your
/*pre-quel sequel to gather the data:*/ Select I changed the following code:
ELSE 'CREATE INDEX ' + +QUOTENAME(index_name) + ' ON ' + +QUOTENAME(SCHEMA_NAME) + '.' + QUOTENAME(OBJECT_NAME) + ' (' + index_columns_key + ')'
ELSE 'CREATE '
WHEN is_unique = 1
THEN 'UNIQUE '
WHEN index_id = 1
THEN 'CLUSTERED '
+ 'INDEX ' + +QUOTENAME(index_name) + ' ON ' + +QUOTENAME(SCHEMA_NAME) + '.' + QUOTENAME(OBJECT_NAME) + ' (' + index_columns_key + ')'