Refactoring Updated
Refactoring rewrites your SQL into a cleaner or safer shape without changing what it does. AKML SQL offers schema-aware operations such as Smart Rename, plus a set of quick text-level rewrites. Find them on the AKML SQL -> Refactor menu and in the Command Palette (Ctrl+Shift+P).
Preview before anything changes
By default every refactoring shows a preview first: a diff of what will change, with checkboxes for individual edits. Nothing is applied until you confirm, and applied changes are undoable with Ctrl+Z. You can turn the preview off in Options, but keeping it on is recommended.
Smart Rename
Renames a table, column, or alias everywhere it appears.
- Right-click the identifier and choose Smart Rename.
- Type the new name.
- Review the list of every occurrence, uncheck any you want to leave alone, and apply.
The rename can cover just the current script or every .sql file in the project directory (set the scope in Options). All approved edits apply as one undo step, and name collisions are blocked before anything changes.
Parameterize Values
Replaces hard-coded literals with declared variables.
-- before SELECT * FROM dbo.Orders WHERE CustomerID = 42 AND OrderDate >= '2026-01-01' -- after DECLARE @CustomerID int = 42; DECLARE @OrderDate date = '2026-01-01'; SELECT * FROM dbo.Orders WHERE CustomerID = @CustomerID AND OrderDate >= @OrderDate;
Variable types are inferred from the literals, and names are derived from the columns they compare against. Uncheck any literal you want to keep hard-coded.
Convert Temp Table
Converts a #temp table to an @table variable, or the reverse. Useful when tuning: table variables suit small row counts, temp tables suit larger ones. The preview warns you about the statistics impact of the direction you picked.
Lightweight refactorings
These run quickly on the current script, still with preview:
- Expand
SELECT *into the explicit column list (uses the live schema) - Expand
INSERTto include an explicit column list - Convert old-style comma joins (
FROM a, b WHERE a.id = b.id) to ANSIJOIN ... ONsyntax - Encapsulate a statement in
BEGIN/END - Add the
ASkeyword to implicit aliases - Qualify object names with their schema prefix
- Add square brackets around identifiers
- Insert missing
;statement terminators - Add
SET NOCOUNT ONto a stored procedure
Settings
Open AKML SQL -> Options… -> Editor (Refactoring section) to control preview, backups, and rename scope. See the Configuration reference for all keys.
Related: Static Code Analysis, Formatting.