How to format all SQL objects in your database

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:

  1. From the ApexSQL Refactor menu, under sub-menu Other formatting, select the Format SQL objects command:

  2. Use the Ctrl + Shift + Alt + T keyboard shortcut.
  3. Right click on a database in the Object Explorer pane select the Format SQL objects command:

Quick tip icon

Quick tip:

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 format all selected scripts, click Create script button, which will open script in the Query editor, then click Execute button.

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: These objects will show as not “Ok” the next time the objects are scanned, and will need to be re-formatted.

 

January 25, 2016