In this Super SQL Tip Software Engineer Andrei Rusitoru explains the fantastic new formatting options available in SQL Prompt 8 from Redgate.
SQL Prompt is a code completion, code formatting, and refactoring tool for SQL Server. It’ll plug into SQL Server Management Studio or Visual Studio. You’ll find you can work more quickly and accurately with SQL queries, as well as standardize across your team by sharing formatting styles and commonly used SQL snippets. Try it free for 28 days at www.red-gate.com/sqlprompt
For more tips for writing SQL effortlessly check out the #SuperSQLTips playlist: https://www.youtube.com/playlist?list=PLhFdCK734P8A_q6XHDXi4CQzys3R0Jw3X
Hello, I’m Andrei Rusitoru and I work for Redgate software.
Today I’m going to show you how to create your own style using the brand new formatting options in SQL Prompt 8.
In SQL Prompt 8 we’ve added our completely re-designed formatting engine, giving you the best possible control over your formatting styles.
Today we are going to go through the new SQL Prompt formatting options in SQL Server Management Studio, but exactly the same functionality is also available in Visual Studio.
In SSMS I’m going to open the SQL Prompt menu at the top here and choose Edit Formatting Styles from the drop-down.
This opens the Formatting styles window where you can see we have already included a couple of example styles to get you started. Keep an eye out for more of these in upcoming releases.
Under “Your Styles” I’m going to click on Create a style to get started. It’s much easier to build your style on an existing one rather than starting completely from scratch.
If you have created styles in previous versions of SQL Prompt then you will find them added here, and you can continue to work on them.
I’m going to use Redgate’s Default Style as a base to build my new style on.
So here are all the options. As you can see we’ve added a lot of functionality to allow you to tweak your style settings.
Each of the main areas of SQL code has a section down the left hand side here, with sub-sections to help you easily find and manage these settings.
To start with, let’s take a look at the GLOBAL settings and set the Whitespace options.
For my tab behaviour, I want to use only tabs and I want 2 spaces in a tab.
As you can see, there is some sample code at the bottom here that updates live as you change your settings so you can see exactly what impact your changes are having.
If you want, you can change this to your own code if you have a query open.
I don’t want to wrap my lines so I’m going to uncheck that.
And finally I want to add a space before my commas.
Let’s check how it looks… that looks good so I’m going to press Save.
My new style has now been added to the menu on the left, and I can see a preview of what it does right here. This is going to be really helpful when I’ve created a few of these.
I can also set the new style as my default active formatting by clicking Set As Active.
I’m now going to go back in and change some other settings, so I click edit at the bottom here.
I like to have my JOIN clauses right aligned to FROM, so I’m going to change that.
I also like to have an extra line between them so I can see them easily.
And I want my AND/OR operators to be aligned to the first list item, so I am going to go down here to the EXPRESSIONS section and change that under Operators.
As you can see, there are lots of options to help you get your SQL looking exactly the way you want it and you can keep tweaking it until it looks perfect.
You can create as many styles as you want too, so if you want a few different versions you can create them and then easily switch between them by simply right-clicking in your code, we are going to cover this in another video soon.
So there you have it, it really is that easy to create your own style using the new formatting options in SQL Prompt 8.