3

I am created one function as Test1(). I want to rename the function as Test11().

   Create  function dbo.Test1()
     returns Datetime
     AS
       BEGIN 
    return (SELECT GETDATE())
    END
    GO
  SELECT  dbo.Test1() 

If possible to rename the function name using query.

0

5 Answers 5

8
exec sp_rename 'dbo.Test1','Test11',object
--1st parameter=Original object name
--2nd parmeter=New name
--3rd parmeter=Objecttype to rename(object,column,index)
Sign up to request clarification or add additional context in comments.

Comments

3

If you're doing it with T-SQL, you'll have to DROP the function and recreate it afterwards:

DROP FUNCTION dbo.Test1;
CREATE FUNCTION dbo.Test11()
RETURNS DATETIME
AS
BEGIN 
    RETURN (SELECT GETDATE())
END

From MSDN:

To rename user-defined functions

This task cannot be performed using Transact-SQL statements. To rename a user-defined function using Transact-SQL, you must first delete the existing function and then re-create it with the new name. Ensure that all code and applications that used the function’s old name now use the new name.

2 Comments

without drop. If possible to rename..@diiN_
@Meline MSDN says that you can't rename it without dropping it first.
2

To rename user-defined functions This task cannot be performed using Transact-SQL statements. To rename a user-defined function using Transact-SQL, you must first delete the existing function and then re-create it with the new name. Ensure that all code and applications that used the function’s old name now use the new name.

https://msdn.microsoft.com/en-us/library/hh510244.aspx

Comments

0

There is no way to rename a procedure/function unless you drop and create it again.

Comments

0

This task cannot be performed using Transact-SQL statements. To rename a user-defined function using Transact-SQL, you must first delete the existing function and then re-create it with the new name. Ensure that all code and applications that used the function’s old name now use the new name

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.