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.
How can I solve it?
This question is related to
sql
sql-server
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.
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:
/* 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
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'
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.
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!
obviously i'd rather know how to do it without a gui but sometimes you've just gotta get sh** done!
Are you running the query in the correct database? i.e.,
Use MyDatabase;
GO
EXEC sp_rename 'ENG_TEst.[ENG_Test_A/C_TYPE]', 'ENG_Test_AC_TYPE', 'COLUMN';
GO
just try to remove the STATISTICS INDEXES linked to this COLUMN.
Best Regards.
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.
This works
EXEC sp_rename
@objname = 'ENG_TEst."[ENG_Test_A/C_TYPE]"',
@newname = 'ENG_Test_A/C_TYPE',
@objtype = 'COLUMN'
Source: Stackoverflow.com