Changing the Default Encoding of SQL files in SSMS

Overview

The default encoding for SSMS sql files is UTF-16, more specifically, either Western European (Windows) - Codepage 1252 or Unicode - Codepage 1200. These encodings play havoc with a git diff as these encoding appear as binary files.

The preferred encoding is Unicode (UTF-8 with asignature) - Codepage 65001

Steps to resolve

  1. From within SSMS, open the sql template file named SQLFile.sql, by default in one of these locations: –
    1. %ProgramFiles%\Microsoft SQL Server\[Sql Version]\Tools\Binn\VSShell\Common7\IDE\SqlWorkbenchProjectItems\Sql\
    2. %ProgramFiles(x86)%\Microsoft SQL Server\[Sql Version]\Tools\Binn\VSShell\Common7\IDE\SqlWorkbenchProjectItems\Sql\
    3. %ProgramFiles%\Microsoft SQL Server\[Sql Version]\Tools\Binn\ManagementStudio\SqlWorkbenchProjectItems\Sql
    4. %ProgramFiles(x86)%\Microsoft SQL Server\[Sql Version]\Tools\Binn\ManagementStudio\SqlWorkbenchProjectItems\Sql
  2. Resave using correct encoding:
    1. File => Save As
    2. Click the arrow next to the Save button
    3. Choose the relevant encoding: Unicode (UTF-8 with asignature) - Codepage 65001

All new query windows will default to UTF-8 files

5 Comments

  1. This will works with “New Query” command. But if you right click on object then select “Modify” command, it will choose UTF-16 LE (code page 1200) as the file’s encoding.

  2. Graeme Geldenhuys

    December 6, 2018 at 1:34 am

    That’s good and well for new query windows, but when you right-click on an existing stored procedure in a database and select “Modify”, than SSMS still defaults to UTF-16 encoding when you save that editor window to disk.

    Any solution or suggestions for that case?

  3. I found that I had to Run SSMS as Administrator in order to save the encoding change to sqlfile.sql.

  4. Doesn’t work in Microsoft SQL Server Management Studio v 14.0.17277.0

  5. Looks like for SSMS 18 it is:
    C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\SqlWorkbenchProjectItems\Sql

    There is also one in:
    C:\Users\jcoryat\AppData\Roaming\Microsoft\SQL Server Management Studio\18.0\Templates\Sql

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.