Rename column returning error

[亡魂溺海] 提交于 2019-12-11 21:21:13

问题


I tried using this procedure to rename badly named columns in SQL Server. The generated statement seems correct:
EXEC sp_rename '[TBL_TAXREPORTtestxxx].["InsertedOn"]', 'InsertedOn', 'COLUMN'

however that gives me the following error:

Msg 15248, Level 11, State 1, Procedure sp_rename, Line 266
Either the parameter @objname is ambiguous or the claimed @objtype (COLUMN) is wrong.

Any clue ?


回答1:


Option 1: You can try to check if you are running the query in the correct database.

Option 2: If yes then try this:

EXEC sp_rename 
@objname = 'TBL_TAXREPORTtestxxx."[InsertedOn]"',   --or @objname = 'TBL_TAXREPORTtestxxx."InsertedOn"'
@newname = 'InsertedOn', 
@objtype = 'COLUMN'

Option 3: If the above also fails then you can try to create a new table with all the names correct and copy the data from the existing table to the new table and drop the previous one. And finally rename the table.

EDIT:

Option 4: As Gordon has said in comments, you might also want to check for schema.

EXEC sp_rename 
@objname = '[dbo].TBL_TAXREPORTtestxxx."[InsertedOn]"',   
@newname = 'InsertedOn', 
@objtype = 'COLUMN'


来源:https://stackoverflow.com/questions/33080541/rename-column-returning-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!