

In this article, we have seen to beautify and format SQL queries using Query designer and edit toolbar options. So, don’t forget to make use of them to make the process much faster. Once you have clicked on the Make Uppercase tool, the selected lines in the SQL query will be automatically converted to uppercase as shown below.Īlso, by now you might have figured out that beside each option in the edit menu, its corresponding shortcut has been mentioned. There are many more options under the edit tab’s advanced option. There are numerous ways in which you can format and design your SQL query.įor example, you want to convert a few sentences or words in the query to capital letters, you can do so using the edit tab from the toolbar as shown below. Next, you will observe that the said lines have been commented successfully. Next, if you wish to comment a few lines in your code, then select those lines and click on Comment out the selected lines tool as shown below. The tool will increase the indent for the selected lines. Suppose if you wish to give some indent for some of the lines in your query, then select those lines and click on Increase Indent. Having seen various options for custom formatting a SQL query in SQL server management studio, let us try a few examples to illustrate the usage of the given commands. If you do not want your edit tab for some reasons, you can use SQL editor and Text editor to format the SQL queries as shown below. So, there are plenty of options to format your query. When you will click on the Edit tab in your SQL management studio, if you will select Advanced option, you will get multiple options such as Tabify Selected Lines, Untabify Selected Lines, Make Uppercase, Comment Selection etc. There are multiple ways of giving indents and changing the length of tab spaces for a SQL query in MS SQL Server management studio. We can even format a query with personal customization, by giving indentations, tab spaces, commenting and uncommenting etc.Ĭustom SQL Query Formatting using SQL Editor, Text Editor and Edit Tools Until now, we have been formatting the query using an automatic query designer. The formatted SQL query would look something as shown below. Modify the query as you want and click on Ok. Just select the query you want to format and press Ctrl+Shift+Q on the keyword.Ī query designer dialog box will appear in front of you. In order to format this SQL query, we will use the shortcut. This might seem like a lot of steps but you can open the query designer by using a shortcut Ctrl+Shift+Q.Ĭode: select * from dbo.books_audit_table where And when you click on Ok and the original query will get formatted automatically as shown below. You can even see the preview of your formatted query in the lower section. Step 3: After you have formatted the query in the desired manner, click on OK. You can select the names of the columns you want in the formatted query and all. Step 2: Once you select the Design Query in Editor option, a Query Designer dialog box as shown below will appear in front of you. Select Design Query in Editor option from it.

On clicking on the Query tab, a drop-down menu as shown below will appear on the screen. In SSMS 2008 it combines nicely with the built-in intelli-sense, effectively providing more-or-less the same base functionality as Red Gate's SQL Prompt (SQL Prompt does, of course, have extra stuff, like snippets, quick object scripting, etc).Step 1: Click on the Query tab in the bar just below the main bar.
Sql formatter online access code#
The SSMS Add-in allows you to set your own hotkey (default is Ctrl- K, Ctrl- F, to match Visual Studio), and formats the entire script or just the code you have selected/highlighted, if any. It's available for immediate/online use at, and just today graduated to "version 1.0" (it was in beta version for a few months), having just acquired support for MERGE statements, OUTPUT clauses, and other finicky stuff.

Late answer, but hopefully worthwhile: The Poor Man's T-SQL Formatter is an open-source (free) T-SQL formatter with complete T-SQL batch/script support (any DDL, any DML), SSMS Plugin, command-line bulk formatter, and other options.
