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 ]
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
Double-check that your table SYSDetails
exists. If the target table doesn't exist you get this error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With