ApexSQL Refactor is a SSMS and Visual Studio add-in which formats and refactors SQL code and objects using 15 code refactors and over 200 formatting options; locates and highlights unused variables, qualifies objects and expands wildcards, encapsulates SQL into views, procedure, safely renames SQL database parameters and objects and splits SQL tables without breaking dependencies.
Installation of ApexSQL Refactor is very simple; double click on the ApexSQL Refactor.exe file which can be downloaded from ApexSQL Downloads page and press the Next button:
In the Host integration step, choose SQL Server Management Studio and/or Visual Studio versions to integrate the add-in into and click the Install button:
More about installation process of add-ins can be found on the How to install ApexSQL add-ins and integrate into host environments e.g. SSMS, Visual Studio page.
All features are placed under the ApexSQL Refactor main menu:
ApexSQL Refactor toolbar:
- Qualify object names add the owner name (schema/user) or aliases name in front of the object
- Wildcard expansion expand wildcards e.g. “*” used in SQL
- Unused variables and parameters detects unused variables and parameters in any statements like Insert, Print, Update, Execute, Where clauses
The Format SQL option formats SQL code and makes it more readable.
Options window is a window in which various formatting options can be set and new formatting profiles created:
To create a new user defined profile, click the New button on the Options window:
To edit a user defined profile, click the Edit button in the Options window:
To export the user defined profiles, click the Export button in the Options window:
Menu for the refactors features:
The Safe rename feature renames the table, views, functions, stored procedures, parameters, table columns without breaking any dependencies:
The Split table feature divides a SQL table into two tables by copying or moving columns from the Primary table box into the Secondary table box:
The Add surrogate key feature replaces a complex natural key with a surrogate key:
The Change parameters feature removes, changes or adds a parameter in a SQL Server procedure or function without breaking the database integrity:
The Replace one-to-many relationship feature isolates the relationship between two tables and add a separate association table:
Batch formatting
These features can format multiple T-SQL objects/scripts at once:
The Format SQL objects feature can format more than one database objects (procedure, functions) with the formatting profile that is specified in the Profile drop-down box at once:
In the Compare window, the SQL script can be seen before and after formatting:
The Format SQL scripts feature formats multiple .sql scripts with the formatting profile that is specified in the Profile drop-down box:
The Convert to code feature converts a SQL script into a language-specific syntax (Java, VB.NET, C#, Perl, PHP):
The Encapsulate code as feature creates a new stored procedure, view, scalar/table inline function by refactoring any valid T-SQL code in the queries:
March 14, 2018