重命名列返回错误 [英] Rename column returning error
问题描述
我尝试使用此过程来重命名 SQL Server 中名称错误的列.生成的语句似乎正确:EXEC sp_rename '[TBL_TAXREPORTtestxxx].["InsertedOn"]', 'InsertedOn', 'COLUMN'
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.
有什么线索吗?
推荐答案
选项 1: 您可以尝试检查是否在正确的数据库中运行查询.
Option 1: You can try to check if you are running the query in the correct database.
选项 2:如果是,那么试试这个:
Option 2: If yes then try this:
EXEC sp_rename
@objname = 'TBL_TAXREPORTtestxxx."[InsertedOn]"', --or @objname = 'TBL_TAXREPORTtestxxx."InsertedOn"'
@newname = 'InsertedOn',
@objtype = 'COLUMN'
选项 3:如果上述方法也失败,那么您可以尝试创建一个名称正确的新表,并将数据从现有表复制到新表并删除前一个表.最后重命名表.
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.
选项 4: 正如 Gordon 在评论中所说,您可能还想检查架构.
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'
这篇关于重命名列返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!