Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats wrong with sp_rename with column?

I am using following SQL command with sp_rename to rename a column.

USE MYSYS;
GO
EXEC sp_rename 'MYSYS.SYSDetails.AssetName', 'AssetTypeName', 'COLUMN';
GO

But it is causing an error:

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

Please suggest how to rename a column using sp_rename.

[ this command I am using found at Microsoft Technet ]

like image 355
Aditya Avatar asked Dec 07 '13 10:12

Aditya


2 Answers

Try this:

USE MYSYS;
GO
EXEC sp_rename 'SYSDetails.AssetName', 'AssetTypeName', 'COLUMN';
GO

sp_rename (Transact-SQL) (msdn):

[ @objname = ] 'object_name'

Is the current qualified or nonqualified name of the user object or data type. If the object to be renamed is a column in a table, object_name must be in the form table.column or schema.table.column. If the object to be renamed is an index, object_name must be in the form table.index or schema.table.index. If the object to be renamed is a constraint, object_name must be in the form schema.constraint.

Quotation marks are only necessary if a qualified object is specified. If a fully qualified name, including a database name, is provided, the database name must be the name of the current database. object_name is nvarchar(776), with no default.

Syntax with a fully qualified name:

USE Database
GO
EXEC sp_rename 'Database.Schema.TableName.ColumnName', 'NewColumnName', 'COLUMN';
GO

If you want to have in the objectname a fully qualified name you should also specified schema. So if your SYSDetails table is in the dbo schema, this code should work for you:

USE MYSYS;
GO
EXEC sp_rename 'MYSYS.dbo.SYSDetails.AssetName', 'AssetTypeName', 'COLUMN';
GO
like image 93
kmatyaszek Avatar answered Nov 03 '22 22:11

kmatyaszek


Double-check that your table SYSDetails exists. If the target table doesn't exist you get this error.

like image 36
naXa Avatar answered Nov 03 '22 23:11

naXa