
Now we can rename the temporary table #Customer column Id name to SlNo using the below script: SP_RENAME '#Customer.ID', 'SlNo', 'COLUMN'Ħ. INSERT INTO #Customer (Id) Values ('100') Renaming a temporary table column name is same as that of the regular table column name.Įxample: Let us create a temporary table #Customer and insert a record by using the below script CREATE TABLE #Customer(Id INT)
#Sql server rename table how to
How to rename temporary table column name To solve this issue we have to enclose column name within square brackets as shown in the below script: SP_RENAME 'Customer.', 'City', 'COLUMN'ĥ.
#Sql server rename table update
Because of this it is not finding the column name in the table definition and failing to update it. The reason for the above error is, sql server treats as three part naming convention and treating City as table name and Name as column name and Customer as Schema. dot symbol) in it’s name, let us try renaming by the below script: SP_RENAME '', 'City', 'COLUMN' dot) symbol in the column nameĮxample: The Customer table created at the beginning of this article has a column City.Name. To solve this issue we have to add two open square brackets at the beginning of PhoneNo column and three closing square brackets at the end of the PhoneNo column as shown below: SP_RENAME 'Customer.]]', 'PhoneNo', 'COLUMN'Ĥ. The reason for the above error is, sql server treats Customer.

Msg 15248, Level 11, State 1, Procedure sp_rename, Line 238Įither the parameter is ambiguous or the claimed (COLUMN) is wrong. Let us try renaming by the below script: SP_RENAME 'Customer.', 'PhoneNo', 'COLUMN' As Square bracket has special meaning it doesn’t work straight forward. Square brackets) symbolĮxample: The Customer table created at the beginning of this article has a column. How to rename table column which is enclosed by “” (i.e. –Modify the stored procedure to refer the new column ALTER PROCEDURE dbo.GetCustomersģ. Let us modify the GetCustomers stored procedure to reflect the new column name using the below script and then verify the stored procedure execution: It will to change in all the places, it is developer’s responsibility to update at all the place. Msg 207, Level 16, State 1, Procedure GetCustomers, Line 4įrom the above result it is clear that column rename using SP_RENAME will just change the column name in the table. Now let us verify whether it is still working after renaming the column CustName to FullName by the previous example: -Get customer table data To avoid such issues, Sql server alerts us by returning the warning when we use SP_RENAME.Įxample:The script at the beginning of this article is creating the stored procedure: GetCustomers and it was working. In this scenario, the sp will start throwing error post the column rename. For example take a scenario where if the old column name is still referred in a stored procedure even after the column rename using sp_rename. SYNTAX: SP_RENAME 'TableName.OldColumnName', 'NewColumnName', 'COLUMN'Įxample 1: Rename Customer table column CustName to FullName using SP_RENAME SP_RENAME 'Customer.CustName', 'FullName', 'COLUMN'īelow is the pictorial representation of the table column rename using SP_RENAMEĢ) Why SP_RENAME returns the warning: “Caution: Changing any part of an object name could break scripts and stored procedures.” when renaming the column name?īasically, sql server returns this warning to alert us to update all the places wherever we are referring this column. Rename table column name using SP_Rename system stored procedureīelow is the SYNTAX of the SP_RENAME system stored procedure for renaming the column name: Create Procedure to get all the records from customer table INSERT INTO dbo.Customer(id, CustName, ]], Add sample records to the Customer table To understand table column rename using SP_RENAME with extensive list of examples, let us first create a Customer table with sample records as depicted in the below image by using the following script:ĬREATE TABLE dbo.Customer(Id INT, CustName NVARCHAR(50), How to rename temporary table variable column name.How to rename temporary table column name.How to rename table column which is enclosed by “” (i.e.Why SP_RENAME returns the warning: “Caution: Changing any part of an object name could break scripts and stored procedures.” when renaming the column name?.Rename table column name using SP_Rename system stored procedure.In this article we will cover the following:

We can use the SP_RENAME system stored to change/rename the table column name. Many times we come across a scenario where we need to rename / change the existing table column name.
