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 users to preserve all user defined SQL formatting settings and reuse them later to format a SQL script or a query. This is particularly helpful if the same convention is used for all 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.
ApexSQL Refactor can:
- Save 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 menu -> ApexSQL Refactor -> Options:
In the profile drop-down list, four built-in formatting profiles can be found (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 window commands for managing user-defined formatting profiles can be found.
New – creates a new formatting profile editable by the user. A name must be provided in order to create a new formatting profile. The author can be changed, and it will be remembered for the next time when creating another formatting profile. The descriptions field is optional and additional information can be entered about that formatting profile:
Copy – If there is a need 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 users to edit any of the user-defined formatting profile. In the Edit profile window, the profile name can be changed, along with 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, the SQL code can be formatted simply with a click on the Format SQL button in the ApexSQL Refactor toolbar:
Other formatting profiles can be selected , 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 that can be found in the Options window:
Export – saving user-defined formatting profiles with all the formatting options settings in one xml file:
Import – gives possibility to import already exported formatting profiles with all formatting options set:
See also
March 5, 2013