I downloaded Visual Studio Code thinking it would be nice to write T-SQL scripts and have the pretty auto-formatting happen as write.
I've already installed the mssql extension.
When creating a new file, the file is a simple plaintext with no extension 'Untitled-1'.
How in the world do I tell VS Code this is a SQL script so it formats correctly?
If I hit Shift+ALT+F, I simply receive the error "There is no formatter for 'plaintext' installed."
If I save the file with the extension '.sql', the format is applied.
However, I don't want to have to save the file... I want it to just be a scratchpad.
Is there any way in VS Code to tell the editor the file should be formatted SQL other than saving the file as an SQL file?
Thanks!
I hope this will be of some help to you.
If I understood you correctly, you can use first this shortcut:
Win: Ctrl+Shift+P / Mac: Cmd+Shift+p
And then type "Change Language Mode".
Also try and visit this link for additional info: https://marketplace.visualstudio.com/items?itemName=cymonk.sql-formatter
Also you can visit this link: https://code.visualstudio.com/docs/languages/overview where you can find additional info about that, for example:
Changing the language for the selected file
In VS Code, we default the language support for a file based on its filename extension. However, at times you may wish to change language modes, to do this click on the language indicator - which is located on the right hand of the Status Bar. This will bring up the Select Language Mode drop-down where you can select another language for the current file.
Tip: You can get the same drop-down by running the Change Language Mode command (Ctrl+K M).
This is what I did to format queries.
Done!
The other methods work, but the easy button is to click on Plain Text on the status bar
and then type in "SQL" to use your favorite installed SQL extension
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With