
Question:
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:
<blockquote>Msg 15248, Level 11, State 1, Procedure sp_rename, Line 238<br /> Either the parameter @objname is ambiguous or the claimed @objtype (COLUMN) is wrong.
</blockquote>Please suggest how to rename a column using sp_rename
.
[ this command I am using found at <a href="http://technet.microsoft.com/en-us/library/ms188351.aspx" rel="nofollow">Microsoft Technet</a> ]
Answer1:Try this:
USE MYSYS;
GO
EXEC sp_rename 'SYSDetails.AssetName', 'AssetTypeName', 'COLUMN';
GO
sp_rename (Transact-SQL) (<a href="https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-rename-transact-sql" rel="nofollow">msdn</a>):
<blockquote>[ @objname = ] 'object_name'
Is the current qualified or nonqualified name of the user object or data type. <strong>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.</strong> 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. <strong>If a fully qualified name, including a database name, is provided, the database name must be the name of the current database.</strong> object_name is nvarchar(776), with no default.
</blockquote>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 <em>objectname</em> a fully qualified name you should also specified <strong>schema</strong>. So if your <em>SYSDetails</em> table is in the <em>dbo</em> schema, this code should work for you:
USE MYSYS;
GO
EXEC sp_rename 'MYSYS.dbo.SYSDetails.AssetName', 'AssetTypeName', 'COLUMN';
GO
Answer2:Double-check that your table SYSDetails
exists. If the target table doesn't exist you get this error.