The Format SQL objects feature allow formatting one or more database objects with the specified formatting profile, without having to script them first.
There are three ways to invoke the Format SQL objects feature. First, you need to select a database from which you want to format objects. Otherwise, when you try to initiate the Format SQL objects feature, you’ll be prompted with the following message:
From the ApexSQL Refactor menu, select the Format SQL objects command:
- Use the Ctrl + Shift + W keyboard shortcut.
Right click on a database in the Object Explorer pane and from the ApexSQL Refactor menu, select the Format SQL objects command:
Before initiating the process of formatting, make sure that you have the appropriate read/write permissions to manipulate the objects in a database. Otherwise, an empty list appears in the Format SQL objects form.
Initiating the feature opens the Format SQL objects form, with the list of all script based objects e.g. stored procedures:
From the Profile drop down list, choose a formatting profile and from the list which objects you want to format.
To directly format all selected scripts, click the Format button, will open a message box which informs that the changes will be made permanent and cannot be rolled back, if you agree click the Yes button:
If you simply want to create a script, to preview it, or execute it yourself, click the Open button, which will open the script to drop selected objects and re-create them, re-formatted.
Additionally, before formatting, you can compare a SQL object’s script as it now and how it will look like after formatting.
Right click on the script object from the list and click the Compare button or use the Ctrl + G shortcut:
The Format SQL objects form allows grouping objects based on the name of the selected column. Drag a column header to the Drag a column header here to group by that column section in order to group the items from the list, based on one or more columns:
Q: What do the icons in the “Ok” column mean?
A: A red cross mark icon indicates that these objects are not formatted for the selected profile from the Profile drop down list and green check mark icon indicates that the objects are already formatted with the selected profile.
Q: Why can’t I select certain rows for formatting?
A: You can check/uncheck only objects that not previously formatted with the selected profile in the Profile drop down list. These objects that previously formatted with the selected profile from Profile drop down list cannot be checked or unchecked.
Q: I formatted some objects with a specific profile already. What happens if I then change the profile?
A: All of these objects will show as not “Ok” the next time the objects are scanned, and will need to be re-formatted.
January 25, 2016