CategorySQL Server

Changing the Default Encoding of SQL files in SSMS


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

SQL Server script to rebuild all indexes on all tables