Prudent use sp_rename modify any object name

Original link: http: //www.lmwlove.com/ac/id820

We modify the object name sqlserver database, you might prefer to use sp_rename system stored procedure to operate, since it compared to the visual look for the list of objects, speed much faster. But why we do not advocate use it, since it might cause some trouble. Also, when using it to change the object name, the database itself will give the following warning:
WARNING: Changing any part of an object name could undermine the scripts and stored procedures.

We now do a simple test, create a simple stored procedure:

create procedure usp_test
as
begin
select 1
end


We do not study the function and syntax of this stored procedure, because this is not the focus of this chapter.

Then use sp_rename to modify the name of usp_test

sp_rename 'usp_test','usp_test_1'


Prompted a warning:
WARNING: Changing any part of an object name could undermine the scripts and stored procedures . But the name has been changed is lost.

At this time, we see from the list of stored procedures Enterprise Manager stored procedure name 'usp_test' has been modified to 'usp_test_1' up. Moreover, we chose right in -> changes name to see the script has been saved as 'usp_test_1', defined as follows:
the ALTER Procedure [dbo] [usp_test_1].
AS
the begin
the SELECT 1
End
but we use sp_helptext system storage procedure to review the definition, you will find the definition found by this method, the name did not change to come :

sp_helptext usp_test_1


Return results as follows:
Create Procedure usp_test  
AS  
the begin  
SELECT. 1  
End
defined in the column definition table sys.sql_modules no modifications come

select definition from  sys.sql_modules  where object_id=object_id('usp_test_1')


Returned the following results:
the Create Procedure usp_test the begin the SELECT 1 AS End

can be seen from this test, I have modified the name of the object in the database, the database may be made in the definition of the object are not synchronized. This may cause some problems, problems such as the following link caused, that is, for this reason produced.

Correction:
again after tests found, not only is the use of sp_name to modify the object name can cause the problem, there will be the problem modify the object name in any way. It seems, when we modify the name of the object to be cautious.

Guess you like

Origin www.cnblogs.com/donelyorjune/p/11105078.html