vstandsforvinay
vstandsforvinay

Reputation: 138

Rename a column with a '.' using sql function sp_rename

I used a query to alter my table column name as follows:

exec sp_rename 'Mobile.Mobileno','Mobile.MobileNum','COLUMN'

Now that I know I had made a mistake by taking the new column name as 'Mobile.MobileNum', is there a way to solve it.

Since when I am using the above query again, I am facing an error.

exec sp_rename 'Mobile.Mobile.MobileNum','MobileNum','COLUMN'

PS: Cannot drop the table or column

Upvotes: 2

Views: 181

Answers (1)

StuartLC
StuartLC

Reputation: 107317

You'll need to escape the erroneous column name with [..]:

exec sp_rename 'Mobile.[Mobile.MobileNum]','MobileNum','COLUMN'

SqlFiddle

Upvotes: 4

Related Questions