User defined SQL formatting profiles in ApexSQL Refactor

ApexSQL Refactor takes formatting to a new level, making maintaining a personal formatting style much easier in multiple-user environment or in companies with strict formatting requirements by allowing them to switch between different formatting styles in a single click

ApexSQL Refactor allows you to preserve all your SQL formatting settings you’ve defined, and reuse them later to format a SQL script or a query. This is particularly helpful if you have to use the same convention as other users, or avoid situations in which a developer prefers SQL to be formatted in a particular way, only to have the formatting repeatedly changed by the DBA when it is submitted for review

With ApexSQL Refactor you can:

  • Save your preferred formatting options to a reusable profile
  • Group and categorize formatting styles
  • Quickly modify existing profiles
  • Avoid formatting conflicts with users

Developers tend to write SQL fast, to get some initial results quickly, and at that point it is usually hard for others to read. By using an individual profile defined via this feature, every developer can format the SQL into a familiar and easily readable layout

To do so, go to ApexSQL main menu -> ApexSQL Refactor -> Options

In the profile drop-down list, you can find four built-in formatting profiles (ApexSQL, Compact, Extended and MSDN SQL BOL), that cannot be changed in any way.

ApexSQL – contains what we determined was a good SQL formatting standard

Compact – makes the SQL code denser

Extended – expands the SQL code with additional spaces, tabs and empty lines

MSDN SQL BOL – mimic formatting settings used in MSDN resource site.

More about formatting profiles can be found on this link.

In the header of the Options dialog you can find commands for managing user-defined formatting profiles.

New – creates a new formatting profile editable by the user. You must provide a name in order to create a new formatting profile. The author can be changed, and it will be remembered for the next time you choose to create another formatting profile. The descriptions field is optional, and you can enter additional information about that formatting profile.

Copy – If you want to make some changes based on an existing profile, use the Copy command. It will create a copy of the currently selected profile. This formatting profile can be edited and renamed later, while preserving the original.

Edit – this command allows you to edit any of the user-defined formatting profile. In the Edit profile window you can change the name, the author or the description of the chosen formatting profile

Delete – This command will delete currently chosen formatting profile.

To set a formatting profile as the default one, select the Set as active button. After the formatting profile is being set as active, you can format the SQL code simply by clicking Format SQL button in the ApexSQL Refactor toolbar.

You can always select the other formatting profile to format your SQL code, from the ApexSQL -> ApexSQL Refactor -> Format SQL by profile

Or from the context menu in the Query editor

There are several more features for the formatting profiles you can find in the Options dialog:

Export – saving user-defined formatting profiles with all the formatting options settings in one xml file

Import – gives you possibility to import already exported formatting profiles with all formatting options set

See also


March 5, 2013