Last Updated: February 25, 2016
·
3.9K
· ChrisMissal

Better Diffs with SQL Files

The default encoding for SQL Server Management Studio is UTF-16. If you are saving a file with this encoding, some diff tools or viewers "think" the file is binary and won't give you a comparison.

Picture

You can prevent this by "Save with Encoding..." as shown below. Just click the down arrow on the save button.

Picture

Now you'll be able to see diffs in GitHub (for instance).

I hope this is helpful, but if you know another way, or better way, I'd love to know about it, thanks!

2 Responses
Add your response

Yeah, UTF-16 .sql files were annoying for me with GitHub diffs.

There is an easier way to make this problem go away:

  1. Find the template is a file named SQLFile.sql, by default in the location %ProgramFiles%\Microsoft SQL Server\[Sql Version]\Tools\Binn\VSShell\Common7\IDE\SqlWorkbenchProjectItems\Sql\.
  2. Resave (using your tip) as UTF-8.
  3. All new query windows will default to UTF-8 files

Source: Microsoft Connect post Unicode Defaults on SSMS Save.

There is a great read at UTF-8 Everywhere explaining why Microsoft is so wedded to UTF-16 (aka "Unicode" in the Microsoft developer world).

over 1 year ago ·

This is perfect, thanks Steve!

over 1 year ago ·