1

When I check my default SSMS file format it is Windows 1252, and opening a saved script inside VSCode is showing me it is UTF-8.

However, when I do a 'generate scripts', all I get is options for 'unicode' and 'ascii'. When I save as unicode it is saving as utf-16 and causing havoc with git. Saving a script using file/save as is fine.

I'm no expert on code pages/encoding but I am presuming saving as 'ascii' really is just ascii and will lose any non-ascii characters that are valid in UTF-8

How do I change this 'script as unicode' from utf-16 to 8, or if that is a daft question, get it to save using the default option I have for standard files?

I'm using version 17.6 of SSMS

enter image description here thanks.

Neil Walker
  • 6,400
  • 14
  • 57
  • 86
  • That doesn't say "ASCII", it says **ANSI**. I might be recalling incorrectly, but I'm pretty sure you *can't* export to UTF-8 with SSMS. SQL Server itself only introduced UTF-8 support recently, and that's only in SQL Server 2019 preview. – Thom A Oct 01 '19 at 16:00
  • sorry, I saw 'ansi' and probably only looked at the first two characters, however, my problem remains, ansi is a 1 byte code. So if you cannot export as utf-8, why can you save a script as anything you like? – Neil Walker Oct 01 '19 at 16:07
  • FYI as well, Windows 1252 isn't an ASCII format, it's an ANSI format, using the codepage 1252. It isn't UTF-8 either. – Thom A Oct 01 '19 at 16:07
  • *"why can you save a script as anything you like"* because you're using a save dialogue box. Generate Scripts isn't quite the same. What you *could* do instead however is use the *"Save to a new query window"* option and then use the Save As dialogue. – Thom A Oct 01 '19 at 16:10
  • ok, i will do that, it's just done by other people. btw @Lamu, I am only saying utf-8 because when you look at the encoding inside Visual Studio Code it says 'utf-8' on a windows-1252 file and this is fine with Git. I'm kind of mixing things up, just saying 'generate' creates encoding not the same as 'save as' – Neil Walker Oct 01 '19 at 16:11
  • Otherwise, if you're generating 1 file per object, you could save them all to a folder, and then use something like Powershell to convert them all (as shown [here](https://stackoverflow.com/a/750453/3484879)). – Thom A Oct 01 '19 at 16:12
  • *"I am only saying utf-8 because when you look at the encoding inside Visual Studio Code it says 'utf-8' on a windows-1252 file."* VSCode will infer the code page/format of the file but that doesn't mean it's correct. Windows 1252 and UTF-8 are completely different. – Thom A Oct 01 '19 at 16:13
  • This could well be, therefore, that you *are* saving them as Windows 1252 when choosing Ansi, but VSCode is assuming it is UTF-8. – Thom A Oct 01 '19 at 16:15
  • I have found the issue, and @Lamu saving to window doesn't actually work either. When you do 'save to new query window' it overwrite your default and changes the codepage to codepage 1200. So you then have to save as and change it again... – Neil Walker Oct 01 '19 at 16:38
  • 2
    `Larnu` not `Lamu`. – Thom A Oct 01 '19 at 17:05

0 Answers0