
In theory, you could extend this technique to include objects such as functions. In this example, all views and stored procedures in the AdventureWorks2014 database have been selected: Right-click on the database, navigate Tasks | Generate Scripts, then select the specific objects you wish to format. One way to speed this up is to script the required objects to a single query window using SSMS’s Generate Scripts wizard.
#Sql server code formatter online code#
If you’ve inherited a new database and are performing a code review, or there is some other reason it might be useful to format many objects in a database, scripting out each of them individually and applying the formatting changes would be impractical for all but the smallest databases. Formatting all scripts for a set of objects The latest version of the tool ( 7.3, currently in beta) also allows users to define multiple custom templates to exert precise control over code layout. In short, with a few key strokes, a developer can use SQL Prompt to transform a script that looks like this … I won’t cover the options in detail here, but check out some of these short videos and it will give you the idea. It also offers a range of options for inserting semi-colons, applying specific casing standards, adding or removing square brackets and more, as you can see: It comes with a couple of pre-installed code formatting templates and simply by selecting Format SQL from the menu, or using the Ctrl+K, Ctrl+Y keyboard shortcut, any script can be auto-formatted according to the selected template. Formatting a single scriptĪ tool such as SQL Prompt can help speed up this process. When asked to review someone else’s code, or perhaps to do some performance tuning on a set of stored procedures, it will slow progress down considerably if the developer needs to reformat each object script manually.


It’s also rare to find two database developers who agree in detail on exactly how SQL code should be formatted. They will struggle to look at, let alone digest and understand, code formatted in a ‘foreign’ style. They like to see the code laid out in a very particular way. Any database developer or DBA who spends much of their working week staring at SQL code quickly becomes set in their ways.
