How to rename scripted objects

The Rename functionality provides an easy way to replace an object name with a new one that better reveals its purpose, and automatically finds and corrects all references to it.

An object can be renamed only in a script, not in a database.

The Rename refactoring is available for:

  • Tables
  • Columns
  • Views
  • Stored procedures
  • Functions
  • Triggers
  • Logins
  • Types
  • Rules
  • Sequences
  • Synonyms
  • Named transactions
  • Cursors
  • Queues
  • Contracts
  • Service
  • Routes
  • Column Master Keys
  • Rules

To rename an object in the SQL editor:

1. In the SQL code editor, place the cursor over the object you want to rename and use one of the following options:

  • Right-click the object and select Rename.
  • Go to the SQL Complete menu and then select Rename.
  • Press F2.

The object will be highlighted.

2. Type a new name for the object. As you type, a tooltip appears instructing you to Press F2 to preview changes or Enter/Tab to apply.

3. To preview the code changes, press F2. In the Preview Changes - Rename dialog that opens, view the code changes and click Apply to apply them.

4. To proceed without preview, press Enter/Tab to apply your changes in the code.

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 procedure using the built-in SSMS Find & Replace functionality. As you can see, the table in the query along with variables and procedure parameters will be renamed as well.

Renaming scripted objects

As opposed to that, SQL Complete analyzes the script and smartly renames objects of the same type. For instance, if your script contains a variable and a column of the same name, and you rename the variable, the column will not be renamed.

Renaming scripted objects

Note

You can undo any action by pressing Ctrl+Z.