I recently started using Management Studio 2012. When using MySQL Workbench, a handy feature was that I could stay all in lower case and any reserved word (like SELECT
, INSERT
) would convert to upper case automatically. How do I replicate this behavior in SSMS?
-
3Does anyone else find this really unworkable? Having to hit CAPS for reserved words then again to type variable names etc? It really slows down my typing.– David FolksmanCommented Aug 22, 2013 at 13:52
-
Of course there is always the option of not making the keywords upper case. Not as easy to read, but you don't have to hit the shift key. :)– Kenneth FisherCommented Aug 22, 2013 at 14:39
-
wow just come back to this. How do I add adverts to this post haha!– David FolksmanCommented Apr 17, 2018 at 14:16
5 Answers
No, Management Studio does not have this native functionality in any version from 2005 -> 2016 CTP 3.2. You may want to check out 3rd party add-ins, like Mladen Prajdić's SSMS Tools Pack or Red-Gate's SQL Prompt, both of which have the capability to format a block of code, including automatically upper-casing keywords. However I don't know of any tool that will do this automatically as you type.
For me, I have been doing it so long, it just comes naturally, and not pressing Shift would actually slow me down. When I get someone else's code where the keywords are lower case, I highlight either the whole block or the offending sections, and hit Ctrl+Shift+U. If I have to highlight the whole section, I then go in to the object / column names and use IntelliSense to case them correctly (I have a real hang-up about ensuring that all keywords are upper case and all entity names match the metadata exactly, because you never know when your code will be deployed to a case sensitive collation).
-
Unbelievable that SSMS does not have this feature built in natively !– nanonerdCommented Mar 23, 2017 at 19:30
In addition to solutions that are already mentioned, I'd suggest using ApexSQL Refactor - a free SSMS and Visual Studio add-in.
ApexSQL Refactor can help you create your own SQL formatting standards. It can be used to distribute and enforce SQL formatting rules among team members. To perform capitalization formatting, it is enough to:
- Download ApexSQL Refactor
- Launch your SQL Server Management Studio or Visual Studio’s and click ApexSQL Refactor on the Main menu
- From the ApexSQL Refactor menu, click the Format T-SQL code option
- Select Formatting options Set the specific option (Capitalization)
- Preview the option’s effect on the current query or a built-in example
Note: Before configuring capitalization standards, ensure your database doesn’t have case-sensitive collation. This can cause big problems when playing with capitalization.
If you wish to learn more, I suggest to read these 2 articles to see how capitalization is handled with ApexSQL Refactor:
-
ApexSQL's tools were great. Unfortunately, since the company was acquired by Quest, they are no longer free.– John MoCommented Mar 7, 2022 at 22:09
One more very simple solution: use notepad++. Inside there is very good plugin called Poor man's sql formatter. The drawback is that you have to paste SQL
inside the notepad++
. But it is free.
There is also poorsql.com, but I did not try it.
-
3He also wrote a plug-in for SSMS. I use it and recommend it all the time. Commented Feb 11, 2016 at 17:24
-
I don't know that I will try it for sure! 10x for the comment @Jonathan Fite! Commented Feb 12, 2016 at 8:37
-
poorsql.com is awesome. Just what I needed (I don't do this very often)– JessCommented Feb 9, 2021 at 14:18
SQL Pretty Printer does it pretty well for me. It's a small and easy-to-install plugin for SSMS. You set up your preferences and then whenever you want to format code, just click the icon on its toolbar.
-
3
I found a hidden gem for auto upper/lower case formatting and indenting in SSMS that I will forever use. No more "New Query".
- Rt-Click table name within Object Explorer
- Edit Top 200 Rows
- QueryDesigner menu option
- Pane
- SQL. Write or drop in some ugly, non formatted SQL. QueryDesigner
- Verify SQL Syntax will UC reserved words and indent for you.
- SQL. Write or drop in some ugly, non formatted SQL. QueryDesigner
- Pane
- QueryDesigner menu option
- Edit Top 200 Rows