Exporting all of the data (including logins, linked servers, SQL Agent jobs, DB Mail settings, etc), and rebuilding the instance-level data, plus reloading all of the user data, is a lot of work. And, even after all of that, there's still no guarantee that you can update a database's default collation via ALTER DATABASE
because there are several conditions that will prevent the operation from completing (please see the "Changing the Database Collation" section of the ALTER DATABASE
documentation for details).
There is, however, an undocumented method that is much easier. The main drawback being that it's unsupported. This is not to say that anything will go wrong, just that if something does, Microsoft won't help fix it (because they never guaranteed that it would work).
The method I speak of is running sqlservr.exe
with the -q {new_collation_name}
switch. There's a little more to it than that, but that is the basic idea. This method simply updates the system meta-data, which has benefits and consequences, the main ones being:
BENEFITS
- pretty fast
- bypass most restrictions that prevent
ALTER DATABASE
from working
- likely far more accurate than any script that people have come up with over the years to drop and recreate objects
DRAWBACKS
- unsupported if something goes wrong
VARCHAR
data can change, IF the code page is different between the old and new collations, and characters with values of 128 - 255 (0x80 - 0xFF) exists, and those characters do not exist as the same character with the same value on the new code page. So the potential is there for data loss, and your data needs to be research first to ensure that this condition does not exist. But, this also means that there are plenty of cases with only characters having values of 0 - 127 which are not in any danger, even if the code page changes.
- User-Defined Table Types (UDTTs) are skipped and need to be updated manually.
For a detailed description of what the sqlservr.exe -q
method does and does not do (including details on how collations work at the various levels, and potential issues to watch out for), please see my post:
Changing the Collation of the Instance, the Databases, and All Columns in All User Databases: What Could Possibly Go Wrong?
To change only the instance (including the system databases: master
, model
, msdb
, and tempdb
) and one or more databases (but not all databases), simply detach the database(s) that you want to exclude from this operation, and then re-attach them once the collation update completes.