The information in this article applies to:
SYMPTOMS
Renaming a Stored Procedure, View or Trigger object will not change the name of the corresponding Stored Procedure, View or Trigger object in the SYSCOMMENTS table. This may cause problems when a script is generated for the renamed object. The script for the renamed object is generated with the old name of the object in the CREATE statement.
CAUSEInternally, SQL Server uses the object_id, which remains the same even if the name of the object has changed through RENAME. WORKAROUNDDo not rename Stored Procedures, Views, or Triggers. Instead, create a script of the existing object, change the name of the object in the CREATE statement of the script, and save the script. The script should now have a DROP statement with the old object name to be dropped. The script should also have the CREATE statement with the new object name. Run the script to create the object with the new name. MORE INFORMATION
The CREATE statement for a renamed Stored Procedure or View can be accessed by double-clicking the renamed Stored Procedure or View in Microsoft SQL Server Enterprise Manager. To generate a script of the Stored Procedure, View or Trigger, right-click the database where the renamed Stored Procedure, View or Trigger was created and select ALL TASKS\GENERATE SQL SCRIPTS. The generated SQL script will have a CREATE statement with the previous name of the Stored Procedure, View or Trigger.
Now rename the stored procedure to "renamedmytest" by right-clicking the stored procedure and selecting RENAME or by using sp_rename 'myrenametest','renamedmytest'.Next, double-click the stored procedure "renamedmytest" and note that the old stored procedure name still appears in the CREATE PROCEDURE statement.
The stored procedure runs in a query window using the new name (exec renamedmytest). If you right-click the database where the renamed stored procedure was created and select ALL TASKS\GENERATE SQL SCRIPTS to generate a script of the renamed stored procedure, the CREATE PROCEDURE statement will have the old procedure name "myrenametest" in the CREATE PROCEDURE statement generated.
For example:
Additional query words:
Keywords : SSrvStProc kbSQLServ650 kbSQLServ700 |
Last Reviewed: December 20, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |