Renaming stored procedures, triggers, user-defined functions, or views

Is this issue handled in Katmai?
[91 byte] By [Siva-Katmai] at [2008-2-15]
# 1
Could you explain why this is an issue? Can't you just drop the existing ones and create the new ones with a different name?

Thanks,

MarcelvanderHolst-MSFT at 2007-10-2 > top of Msdn Tech,SQL Server Katmai,SQL Server Katmai Database Engine...
# 2

Thanks for your kind reply.

But i asked without dropping those objects.

If we use sp_rename means, it'll not affect the syscomments table..

For that only i mentioned it "issue".

Siva-Katmai at 2007-10-2 > top of Msdn Tech,SQL Server Katmai,SQL Server Katmai Database Engine...
# 3
Sivakumar Rangasamy wrote:

If we use sp_rename means, it'll not affect the syscomments table..

Are you referring to the text column in sys.syscomments? By design, the name of the object will not get updated in the text column if it is renamed because the text column returns the actual, original text of the SQL definition statement. The text (and name of the object) will only get updated if you drop and then recreate the object. This is the same behavior as the definition column of the sys.sql_modules catalog view.

SaraTahir[MSFT] at 2007-10-2 > top of Msdn Tech,SQL Server Katmai,SQL Server Katmai Database Engine...
# 4

Fine.

If we want to change the original text means, drop and recreate the object or else alter that particular object.

Here my question is if we use sp_rename sp means, the object name only renamed.

What about dependency things (like object’s text)?

Is it valid?

SivakumarRangasamy at 2007-10-2 > top of Msdn Tech,SQL Server Katmai,SQL Server Katmai Database Engine...
# 5
SQL Server maintains references in multiple forms:

1. By id (FK constraint, schema binding reference, index to table, table to trigger, view to base tables etc)
2. By name (SP reference (non-schema bound), function reference (non-schema bound), 3/4-part names etc). This type of non-schema bound reference is also tracked loosely by SQL Server and not enforced.

Now, when you use sp_rename we only change the name of the entity (table, view, module, constraint etc) in the metadata. We do not change the text that provides the definition for the object. This is because for compilation purposes like SPs or functions or triggers, the name in the text doesn't matter and it is just part of valid syntax for the CREATE PROCEDURE/FUNCTION/TRIGGER statement. The name is stored separately from the actual definition of the object and that is what gets used. The name in the definition is parsed at create time and that is pretty much it.

So when you modify the name of a SP you will have to go and fix the other modules that reference it. SQL Server cannot do this by itself because there is logical dependency that will be too expensive to evaluate and modify. And in cases where dynamic SQL is used it is not possible at all due to the runtime nature and control of flow logic or unknown values of variables.

SQL Server 2008 however has new object dependency reporting features that will help you identify most of the references easily. Start with the following topic in the new BOL:

http://msdn2.microsoft.com/en-us/library/bb677168(SQL.100).aspx

Understanding dependencies topic:
http://msdn2.microsoft.com/en-us/library/ms345449(SQL.100).aspx

# 6

Thank You!!

Is it feasible, to renaming object through a command?

SivakumarRangasamy at 2007-10-2 > top of Msdn Tech,SQL Server Katmai,SQL Server Katmai Database Engine...
# 7
I am not sure about your question. Are you asking if there is a DDL instead of system SP to rename an object? If so, there is none. Renaming an object is a special operation and each RDBMS has its own way of doing it. The ANSI SQL standards only has ALTER DDL to change objects or object definition. So this is a special operation and proprietary to the implementation of the database engine.
# 8
Umachandar Jayachandran - MS wrote:
I am not sure about your question. Are you asking if there is a DDL instead of system SP to rename an object? If so, there is none. Renaming an object is a special operation and each RDBMS has its own way of doing it. The ANSI SQL standards only has ALTER DDL to change objects or object definition. So this is a special operation and proprietary to the implementation of the database engine.

Here my query is, Not only DDL statements.

In sp_rename sp, “DBCC RENAMECOLUMN” is used for renaming a column.

Here renaming a column process is also have numerous of dependancies.

Like that am asking……

SivakumarRangasamy at 2007-10-2 > top of Msdn Tech,SQL Server Katmai,SQL Server Katmai Database Engine...
# 9
I still do not get your question. Can you elaborate more giving some examples?
# 10

In sp_rename stored procedure, “dbcc renamecolumn” Command used to rename a column. (The column in table can also have a so many dependencies).

For that only I’m asked, “Is it feasible, to renaming object(stored procedure) through a command?”.

SivakumarRangasamy at 2007-10-2 > top of Msdn Tech,SQL Server Katmai,SQL Server Katmai Database Engine...
# 11
No. You can't use these internal DBCC commands outside of system stored procedures and the mechanism to change the metadata depends on the type of object that is being renamed. You need to use the system SP only.

SQL Server Katmai

Site Classified