{"id":1688,"date":"2018-12-22T15:23:43","date_gmt":"2018-12-22T15:23:43","guid":{"rendered":"http:\/\/www.theSQLReport.com\/?p=1688"},"modified":"2018-12-24T14:08:21","modified_gmt":"2018-12-24T14:08:21","slug":"changing-the-sql-server-default-collation-without-reinstall-or-rebuilding-the-master-database","status":"publish","type":"post","link":"http:\/\/www.theSQLReport.com\/?p=1688","title":{"rendered":"Changing the SQL Server Default Collation Without Reinstall or Rebuilding the Master Database"},"content":{"rendered":"<p><strong>Warning: this method of changing SQL Server&#8217;s default collation is not supported by Microsoft<\/strong><\/p>\n<p>The issue was an instance of SQL Server was installed with the default collation (SQL_Latin1_General_CP1_CI_AS), and the software vendor was requesting that the default collation be set to &#8216;SQL_Latin1_General_CP850_BIN2&#8217;. With our security already setup in the Master database for this instance, we did not want to reinstall SQL Server or have the Master database rebuilt (Microsoft&#8217;s recommended resolution).<\/p>\n<h6><em>Note: example below done on virtual edition of SQL Server 2016 Developer edition and not a production system.<\/em><\/h6>\n<h3><strong>Below is the steps taken to change the default collation for the SQL Server Instance, tested to work as far back as SQL Server 2005.<\/strong><\/h3>\n<p>1. In a SQL Server query window, check what is the current SQL Server&#8217;s default collation.<\/p>\n<pre>SELECT SERVERPROPERTY('COLLATION') AS 'DEFAULT COLLATION';<\/pre>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/Finding_Default_Collation.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1691 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/Finding_Default_Collation.jpg\" alt=\"SELECT SERVERPROPERTY('COLLATION') AS 'DEFAULT COLLATION';\" width=\"466\" height=\"173\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/Finding_Default_Collation.jpg 466w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/Finding_Default_Collation-300x111.jpg 300w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/Finding_Default_Collation-210x78.jpg 210w\" sizes=\"(max-width: 466px) 100vw, 466px\" \/><\/a><\/p>\n<p>In this example, the installation of SQL Server 2016 Developer edition defaulted to &#8216;SQL_Latin1_General_CP1_CI_AS&#8217; for this instance.<\/p>\n<p>2.\u00a0 Make backups of all the databases on the instance of SQL Server being worked on.\u00a0 Important to verify that all the databases were backed up before continuing.\u00a0 The best way to backup, if the server is virtualized, is to snapshot the server.<\/p>\n<p>3. When the collation is changed for the instance, all attached databases will also have its collation changed.\u00a0 Check the collation of all the databases on the instance.\u00a0 <strong>Detach any database that the collation should not be changed to the new default for the SQL Server instance.<\/strong><\/p>\n<pre>select name, collation_name from sys.databases;<\/pre>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/CheckCollation.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1702 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/CheckCollation.jpg\" alt=\"select name, collation_name from sys.databases;\" width=\"380\" height=\"209\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/CheckCollation.jpg 380w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/CheckCollation-300x165.jpg 300w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/CheckCollation-210x116.jpg 210w\" sizes=\"(max-width: 380px) 100vw, 380px\" \/><\/a><\/p>\n<p>4. In a SQL Server query window, find the root directory where the SQL Server executable file and save for step 7.<\/p>\n<pre>declare @rootdir nvarchar(500)\r\nexec master.dbo.xp_instance_regread\r\nN'HKEY_LOCAL_MACHINE',\r\nN'SOFTWARE\\Microsoft\\MSSQLServer\\Setup',\r\nN'SQLPath', @rootdir OUTPUT\r\n\r\nSELECT @rootdir + '\\binn' as 'RootDirectoryPath'<\/pre>\n<p>Thanks to <a href=\"http:\/\/sqlworkbook.blogspot.com\/2012\/10\/determine-t-sql-to-find-root-directory.html\" target=\"_blank\" rel=\"noopener\">Sandeep Arora<\/a> for providing the query listed above.<\/p>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/RootDirectoryPath.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1698 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/RootDirectoryPath.jpg\" alt=\"Root Directory Path\" width=\"499\" height=\"228\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/RootDirectoryPath.jpg 499w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/RootDirectoryPath-300x137.jpg 300w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/RootDirectoryPath-210x96.jpg 210w\" sizes=\"(max-width: 499px) 100vw, 499px\" \/><\/a><\/p>\n<p>5. Shutdown the instance of SQL Server.<\/p>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/StoppingSQLServer.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1705 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/StoppingSQLServer.jpg\" alt=\"Stopping SQL Server Service\" width=\"479\" height=\"132\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/StoppingSQLServer.jpg 479w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/StoppingSQLServer-300x83.jpg 300w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/StoppingSQLServer-210x58.jpg 210w\" sizes=\"(max-width: 479px) 100vw, 479px\" \/><\/a><\/p>\n<p>6.\u00a0 Open a command prompt in Administrator mode.\u00a0 On Windows Server 2012 R2, right clicking on the Windows Start button will offer the Administrative Command Prompt in the menu.\u00a0 If the command prompt is not in the administrator mode, a permission error may occur when attempting to start the SQL Server instance.<\/p>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/WindowsServer2012AdminCommandPrompt.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1706 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/WindowsServer2012AdminCommandPrompt.jpg\" alt=\"Administrative Command Prompt\" width=\"301\" height=\"429\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/WindowsServer2012AdminCommandPrompt.jpg 301w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/WindowsServer2012AdminCommandPrompt-210x300.jpg 210w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/WindowsServer2012AdminCommandPrompt-147x210.jpg 147w\" sizes=\"(max-width: 301px) 100vw, 301px\" \/><\/a><\/p>\n<p>7. Change the root directory to where SQL Server&#8217;s executable exists in the directory found in step 4.<\/p>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/ChangeToSQLRootDirectory.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1707 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/ChangeToSQLRootDirectory.jpg\" alt=\"cd to the root directory of the SQL Server executable file\" width=\"675\" height=\"123\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/ChangeToSQLRootDirectory.jpg 675w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/ChangeToSQLRootDirectory-300x55.jpg 300w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/ChangeToSQLRootDirectory-210x38.jpg 210w\" sizes=\"(max-width: 675px) 100vw, 675px\" \/><\/a><\/p>\n<p>8.\u00a0 Start SQL Server in the command prompt with with the switches listed below:<\/p>\n<pre>sqlservr -m -T4022 -T3659 -s\"&lt;instance name&gt;\" -q\"&lt;new collation&gt;\"<\/pre>\n<p style=\"padding-left: 30px;\">-m\u00a0 &#8212; starts SQL Server in single user mode and does not let other&#8217;s users connect<\/p>\n<p style=\"padding-left: 30px;\">-s\u00a0 &#8212; specifics the instance of SQL Server that is being started (use MSSQLSERVER if not using a named instance)<\/p>\n<p style=\"padding-left: 30px;\">-T4022 &#8212; has SQL Server not run any stored procedures that have been configured as part of the startup process<\/p>\n<p style=\"padding-left: 30px;\">-T3659 &#8212; logs all errors to error log during the SQL Server startup<\/p>\n<p style=\"padding-left: 30px;\">-q &#8212; the undocumented switch that changes the default collation for the SQL Server instance<\/p>\n<p>This will run SQL Server in a single user node while displaying the error log in the command prompt window.<\/p>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/starting_sqlservr.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1710 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/starting_sqlservr.jpg\" alt=\"start sqlservr\" width=\"1235\" height=\"489\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/starting_sqlservr.jpg 1235w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/starting_sqlservr-300x119.jpg 300w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/starting_sqlservr-768x304.jpg 768w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/starting_sqlservr-1024x405.jpg 1024w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/starting_sqlservr-210x83.jpg 210w\" sizes=\"(max-width: 1235px) 100vw, 1235px\" \/><\/a><\/p>\n<p>If there are databases attached to the instance, entries into the error log will be displayed as the indexes for each database are altered.\u00a0 This processes may take minutes or hours depending on the number and size of databases.<\/p>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/index_restored.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1711 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/index_restored.jpg\" alt=\"changing collation - index restored\" width=\"1014\" height=\"564\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/index_restored.jpg 1014w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/index_restored-300x167.jpg 300w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/index_restored-768x427.jpg 768w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/index_restored-210x117.jpg 210w\" sizes=\"(max-width: 1014px) 100vw, 1014px\" \/><\/a><\/p>\n<p>9.\u00a0\u00a0 Stopping SQL Server when finished, type ctrl-c to stop and type a Y and click the enter button.<\/p>\n<p><strong>Important: do not stop until the following two lines are displayed:<\/strong><\/p>\n<p style=\"padding-left: 30px;\"><em><strong>The default collation was successfully changed.<\/strong><\/em><br \/>\n<em><strong>Recovery is complete. This is an informational message only. No user action is required.<\/strong><\/em><\/p>\n<p>If the SQL Server instance is stopped before it has a chance to update all the indexes in the attached databases, it will revert back to the original default collation.\u00a0 A lesson this author learned the hard way.<\/p>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/stopping_sqlservr.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1712 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/stopping_sqlservr.jpg\" alt=\"stop sqlservr\" width=\"1230\" height=\"152\" \/><\/a><\/p>\n<p>10. Restart SQL Server normally, and verify the new default collation.<\/p>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/NewDefaultCollation.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1713 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/NewDefaultCollation.jpg\" alt=\"altered default server collation\" width=\"457\" height=\"137\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/NewDefaultCollation.jpg 457w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/NewDefaultCollation-300x90.jpg 300w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/NewDefaultCollation-210x63.jpg 210w\" sizes=\"(max-width: 457px) 100vw, 457px\" \/><\/a><\/p>\n<p>Also, verify that the databases collation have been altered.<\/p>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/NewDatabasesCollation.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1714 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/NewDatabasesCollation.jpg\" alt=\"altered databases collation\" width=\"384\" height=\"209\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/NewDatabasesCollation.jpg 384w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/NewDatabasesCollation-300x163.jpg 300w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/NewDatabasesCollation-210x114.jpg 210w\" sizes=\"(max-width: 384px) 100vw, 384px\" \/><\/a><\/p>\n<p>If there are any detached databases, this would be the time to re-attach them.<\/p>\n<p><strong>Note about &#8220;Net Start&#8221; method to change the default collation:<\/strong><\/p>\n<p>If choosing to use the &#8220;net start&#8221; method of changing the instance&#8217;s default collation, it is best to detach all of the users databases before running this command.\u00a0 The problem the author found using this command, if not all the user databases are detached, there is the lack of notification when SQL Server is done changing the collation for all the user databases.\u00a0 If SQL Server is started before the collation change process is completed, the original collation will reverted back.<\/p>\n<p>If using the &#8220;net start&#8221; method with attached user databases, monitor the errorlog though Windows Explorer.\u00a0 Do not stop the SQL Server Instance until the line appears: &#8220;Recovery is complete.&#8221;<\/p>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/Using_Net_Start.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1717 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/Using_Net_Start.jpg\" alt=\"Recovery is complete\" width=\"1158\" height=\"488\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/Using_Net_Start.jpg 1158w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/Using_Net_Start-300x126.jpg 300w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/Using_Net_Start-768x324.jpg 768w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/Using_Net_Start-1024x432.jpg 1024w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2018\/12\/Using_Net_Start-210x88.jpg 210w\" sizes=\"(max-width: 1158px) 100vw, 1158px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Warning: this method of changing SQL Server&#8217;s default collation is not supported by Microsoft The issue was an instance of SQL Server was installed with the default collation (SQL_Latin1_General_CP1_CI_AS), and &hellip; <a class=\"readmore\" href=\"http:\/\/www.theSQLReport.com\/?p=1688\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":1712,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[139,140,142,141],"class_list":["post-1688","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql-server","tag-collation","tag-sqlservr","tag-t3659","tag-t4022"],"_links":{"self":[{"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts\/1688"}],"collection":[{"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1688"}],"version-history":[{"count":22,"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts\/1688\/revisions"}],"predecessor-version":[{"id":1722,"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts\/1688\/revisions\/1722"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/media\/1712"}],"wp:attachment":[{"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1688"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}