用'重命名列。使用sql函数sp_rename

时间:2021-09-08 10:36:16

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.

现在我知道我犯了一个错误,把新的列名叫做“Mobile”。有办法解决这个问题吗?

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

不能删除表格或列

1 个解决方案

#1


4  

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

您需要使用[..]来避免错误的列名:

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

SqlFiddle

SqlFiddle

#1


4  

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

您需要使用[..]来避免错误的列名:

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

SqlFiddle

SqlFiddle