SQL Complete generates aliases automatically for tables, views, table-valued functions, and synonyms.
You can rename default aliases directly in the code. All references to the renamed aliases will be automatically replaced with the relevant ones.
1. In the SQL code editor, place the cursor over the alias you want to rename and use one of the following options:
The alias will be highlighted.
2. Enter a new name for the alias. As you type, a tooltip appears instructing you to Press F2 to preview changes or Enter/Tab to apply.
3. Optional: To display the preview dialog, press F2. In the Preview Changes - Rename dialog that opens, preview the code changes and click Apply to apply them.
4. To proceed without preview, press Enter/Tab to apply your changes in the code.
Note
In case the alias and the column name are the same, the renaming of the alias does not affect the column name.
Let’s take the following procedure as an example:
CREATE OR ALTER PROCEDURE Person.EmailAddressID
@EmailAddress VARCHAR(30) = '%'
AS
DECLARE @EmailAddressList VARCHAR(30)
SELECT
email.EmailAddressID AS EmailID
FROM Person.EmailAddress email
WHERE email.EmailAddress LIKE @EmailAddress;
GO
EXECUTE Person.EmailAddressID @EmailAddress = 'adriana%'
GO
Try to rename the alias in the query using the built-in SSMS Find & Replace functionality. As you can see, the names of the procedure and its parameters have been changed as well.
Now, try to rename the alias in the query with the SQL Complete Refactoring feature. As you can see, the renaming of aliases does not cause the renaming of the procedure and its parameters.
Note
You can undo any action by pressing Ctrl+Z.