SQL 我该如何解决“参数@objname 不明确或声称的@objtype (COLUMN) 是错误的。”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3091609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can i solve "Either the parameter @objname is ambiguous or the claimed @objtype (COLUMN) is wrong."?
提问by Penguen
If I try to execute below query:
如果我尝试执行以下查询:
EXEC sp_rename 'ENG_TEst.[ENG_Test_A/C_TYPE]', 'ENG_Test_AC_TYPE', 'COLUMN'
I get an error:
我收到一个错误:
Either the parameter@objname is ambiguous or the claimed @objtype (COLUMN) is wrong.
要么参数@objname 不明确,要么声明的@objtype (COLUMN) 是错误的。
How can I solve it?
我该如何解决?
采纳答案by Philip Kelley
Nuts. I hit this same error weeks ago, and after a lot of wasted time figured out how to make it work--but I've since forgotten it. (Not much help, other than to say yes, it can be done.)
坚果。几周前我遇到了同样的错误,在浪费了很多时间之后想出了如何让它工作 - 但我已经忘记了。(没有太大帮助,除了说是,它可以做到。)
Have you tried different combinations of brackets, or of with and without brackest? e.g.
您是否尝试过不同的括号组合,或者有和没有括号的组合?例如
EXEC sp_rename 'ENG_TEst.ENG_Test_A/C_TYPE', 'ENG_Test_AC_TYPE', 'COLUMN';
EXEC sp_rename '[ENG_TEst].[ENG_Test_A/C_TYPE]', 'ENG_Test_AC_TYPE', 'COLUMN';
EXEC sp_rename '[ENG_TEst].[ENG_Test_A/C_TYPE]', '[ENG_Test_AC_TYPE]', 'COLUMN';
EXEC sp_rename '[ENG_TEst].ENG_Test_A/C_TYPE', 'ENG_Test_AC_TYPE', 'COLUMN';
If all else fails, there's always
如果一切都失败了,总会有
- Create new table (as "xENG_TEst") with proper names
- Copy data over from old table
- Drop old table
- Rename new table to final name
- 使用适当的名称创建新表(如“xENG_TEst”)
- 从旧表复制数据
- 放下旧桌子
- 将新表重命名为最终名称
回答by Orlando
This works
这有效
EXEC sp_rename
@objname = 'ENG_TEst."[ENG_Test_A/C_TYPE]"',
@newname = 'ENG_Test_A/C_TYPE',
@objtype = 'COLUMN'
回答by Joe Stefanelli
Are you running the query in the correct database? i.e.,
您是否在正确的数据库中运行查询?IE,
Use MyDatabase;
GO
EXEC sp_rename 'ENG_TEst.[ENG_Test_A/C_TYPE]', 'ENG_Test_AC_TYPE', 'COLUMN';
GO
回答by Jim B
I ran into this today and got it to work with:
我今天遇到了这个问题并让它工作:
EXECUTE sp_rename N'dbo.table_name.original_field_name', N'new_field_name', 'COLUMN'
To get this syntax, I followed Martin Smith's advice above - open up the table in design view, rename the column and then click table designer | generate change script. This produced the script below which does the renaming in two steps:
为了获得这种语法,我遵循了上面 Martin Smith 的建议 - 在设计视图中打开表,重命名列,然后单击表设计器 | 生成更改脚本。这产生了以下脚本,该脚本分两步进行重命名:
/* To prevent any potential data loss issues, you should review this script in
detail before running it outside the context of the database designer.*/
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
GO
EXECUTE sp_rename N'dbo.table_name.original_field_name', N'Tmp_new_field_name_1', COLUMN'
GO
EXECUTE sp_rename N'dbo.table_name.Tmp_new_field_name_1', N'new_field_name', 'COLUMN'
GO
ALTER TABLE dbo.table_name SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
回答by Rob Ganly
i also had this issue- very annoying and haven't found a satisfactory sql answer myself yet (aside from long-winded ones involving creating temp tables etc.) and i didn't have time to explore it to the conclusion i'd have liked.
我也有这个问题 - 非常烦人,我自己还没有找到令人满意的 sql 答案(除了涉及创建临时表等的冗长的问题),我没有时间探索它得出我有的结论喜欢。
In the end just used SQL Server Management Studio to do it by selecting the table, right-clicking on the column and hitting rename. simples!
最后只是使用 SQL Server Management Studio 来完成它,方法是选择表,右键单击列并点击重命名。简单!
obviously i'd rather know how to do it without a gui but sometimes you've just gotta get sh** done!
显然我宁愿知道如何在没有 gui 的情况下做到这一点,但有时你只需要完成 sh** !
回答by Martin Smith
Both of the following work (as discussed here).
以下两项工作(如此处所述)。
exec sp_rename 'ENG_TEst.[[ENG_Test_A/C_TYPE]]]' ,
'ENG_Test_A/C_TYPE', 'COLUMN'
exec sp_rename 'ENG_TEst."[ENG_Test_A/C_TYPE]"' ,
'ENG_Test_A/C_TYPE', 'COLUMN'
回答by stink
I got this error when Updating code first MVC5 database. Dropping (right click, delete) all the tables from my database and removing the migrations from the Migration folder worked for me.
更新代码第一个 MVC5 数据库时出现此错误。从我的数据库中删除(右键单击,删除)所有表并从 Migration 文件夹中删除迁移对我有用。
回答by Greg
I tried every possible solution on this web site and nothing worked for me. I ended up doing in the design mode. Right click on the table name and then click design. Then I changed the name and saved here. Worked simply.
我在这个网站上尝试了所有可能的解决方案,但没有任何效果对我有用。我最终在设计模式下做。右键单击表名,然后单击设计。然后我更改了名称并保存在这里。工作简单。
回答by Pericles Sevegnani
just try to remove the STATISTICS INDEXES linked to this COLUMN.
只需尝试删除链接到此列的统计索引。
Best Regards.
此致。