SQL Refactor - 1.3
Learning SQL Refactor - 1.3
Smart Rename
The Smart Rename refactoring generates a script to rename objects in your database without breaking dependencies so that the integrity of your database is maintained. You can also use this feature to change the object owner.
You can rename the following:
- database objects:
- tables
- views
- stored procedures
- user-defined functions
- parameters in:
- stored procedures
- user-defined functions
- columns in:
- tables
- views
You can use Smart Rename to rename encrypted objects in SQL Server 2000 if you are a member of the sysadmin server role; you cannot use this feature to rename encrypted objects in SQL Server 2005.
You are advised to back up your database prior to running the rename script.
When an object is renamed, SQL Refactor:
- changes the definition
When you run the Smart Rename script, the object definition is modified and SQL Refactor ensures that the sys.sql_modules table (for SQL Server 2005) or the syscomments table (for SQL Server 2000) remains consistent.
- modifies any objects that reference the renamed object so that dependencies are not broken
The following referencing objects are modified if necessary:
- procedures
- views
- functions
- DML triggers
- DDL triggers
- queues (if the owner or name of a stored procedure is changed)
- defaults (if the owner or name of a function is changed)
- computed columns (if the owner or name of a function is changed)
- changes self-referencing (for recursive stored procedures and functions)
- fixes the name of the object to be renamed, if necessary
If you have previously renamed an object using SQL Server Management Studio or Enterprise Manager Rename or the Transact-SQL sp_rename command, the object definition will contain the original name. SQL Refactor fixes the object definition so that it is consistent with the new name. For more information about the sp_rename command, see SQL Server Books Online.
Note that any objects that reference the original name (the name prior to using sp_rename) are not updated.
- fixes the name of any referencing objects that are to be modified, if necessary
If you have previously renamed a referencing object using SQL Server Management Studio Rename or the Transact-SQL sp_rename command, the object definition will contain the original name. SQL Refactor fixes the object definition of the referencing object so that it is consistent with its current name.
The original permissions and extended properties of the object are preserved.
To rename an object:
- On the SQL Refactor menu click Smart Rename, or in the Object Explorer pane, right-click the object and click
Smart Rename.The Smart Rename dialog box is displayed.

- If you want to change the object owner, select the name of the new owner.
- If you want to change the object name, type the new name.
- Click Next.
SQL Refactor checks that the name is not already in use. If the name is valid, SQL Refactor generates the script and displays summary information:

- Action Plan is a summary of the actions that the script will perform, in the order in which they will occur.
- Warnings displays information that you should consider prior to running the script, and reasons the script might fail.
The warnings are graded according to severity.
- Referencing Objects lists the objects that will be modified by the script because they reference the object that is being renamed.
The action plan and warnings are included in the generated script, below the header. If you do not want to include this information in the script, clear the Include summary in the generated script check box.
- Click View Script.
The Smart Rename dialog box is closed, and the SQL script is displayed in the SQL Server Management Studio query editor. Review the script, and then run it to rename the object and modify the referencing objects.
Note that when you run the script, the Object Explorer is not updated with the new name. You must refresh the list to update the name that is displayed.
See also |
Was this article helpful?
SQL Refactor
- Menu item grayed out
- Removing menu items after uninstalling SQL Prompt and SQL Refactor
- Installation fails when Management Studio is not installed (version 1.1)
- SmartRename is greyed out
- Installer doesn't recognise that SSMS is installed
- Dependency creation in Smart Rename
- Add-in failing to load into SQL Server Management Studio on Vista
- Removing SQL Server Management Studio Integration after uninstallation
- Layout SQL Error
- Log files
all SQL products
- Compatibility of Red Gate tools in 64-bit environments
- Application has encountered an error and needs to close
- Error message after installing SQL Toolbelt - The description for Event ID ( 1 ) in Source ( nview_info ) cannot be found.
- Changing the temporary directory used by the installer
- Toolbelt Installer "hanging" while "scanning volumes"
- Login failing with "trusted SQL Server connection" error when using RunAs
all products
- Some Red Gate products identified as containing a trojan by Anti-Virus software
- Activation may fail with Unknown Error -1
- Product uses web help although a CHM file is available locally
- Argument exception resulting from missing environment variable
- Check for updates may fail when used through proxies
- 'Unidentified Publisher' error when repairing or uninstalling
- Licensing activates product as standard edition
- Moving Red Gate software products to another machine
- Red Gate tools log locations
- The application UI opening slowly when there is no internet access
SQL Refactor
- Activating your products
- Activating your products
- Getting help offline
- SQL Refactor release notes - version 1.xx
all SQL products
all products
- Red Gate product acknowledgements
- Activating your products
- Activating your products
- Red Gate bundle history
- Check for updates
- Troubleshooting Check for Updates errors
- Current versions
- Deactivating your products
- Installing Red Gate products from the .msi file
- Requesting additional activations
- Serial numbers for bundles
- Reactivating using a different serial number
- Extending your trial
- Finding your serial numbers
- Moving a serial number from one computer to another
- No response received for manual activation
- Licensing and activation resources
- Licensing and activation resources
- Troubleshooting licensing and activation errors
- Licensing and activation FAQs
- Red Gate tools log file locations
- Download old versions of products
- Download product prerequisites & utilities
- Support & upgrades
- Upgrading your software
- Upgrading FAQs

Refactorings
Options