December 31, 2013 at 1:24 pm
I need to rename a foreign key. It is on a table which is not dbo.
Here is what I run:
exec sp_rename
@objname ='schema_name.table_name.FK_old_name',
@newname ='FK_new_name',
@objtype ='Object'
I get a message :
Msg 15248, Level 11, State 1, Procedure sp_rename, Line 321
Either the parameter @objname is ambiguous or the claimed @objtype (Object) is wrong.
Inside of sp_rename, it selects object_id(@objname) to validate names. Where @objname is my FK_old_name. It returns null, hence it raises above error.
If I run same code outside of sp, it returns null.
Now, how I can get around it? Do I pass parameter for @objname properly?
Thanks
December 31, 2013 at 1:28 pm
SQL Guy 1 (12/31/2013)
I need to rename a foreign key. It is on a table which is not dbo.Here is what I run:
exec sp_rename
@objname ='schema_name.table_name.FK_old_name',
@newname ='FK_new_name',
@objtype ='Object'
I get a message :
Msg 15248, Level 11, State 1, Procedure sp_rename, Line 321
Either the parameter @objname is ambiguous or the claimed @objtype (Object) is wrong.
Inside of sp_rename, it selects object_id(@objname) to validate names. Where @objname is my FK_old_name. It returns null, hence it raises above error.
If I run same code outside of sp, it returns null.
Now, how I can get around it? Do I pass parameter for @objname properly?
Thanks
to rename a foreign key, you only include the name; not the schema/object.
sp_rename 'FK_oldname','FK_newname','OBJECT'
actually, everything except a table(constraints,pk's, defaults, etc) is the name of the object only; only a table can you references the schema as well.
Lowell
December 31, 2013 at 1:32 pm
Technet article on sp_rename says:
If the object to be renamed is a constraint, object_name must be in the form schema.constraint.
No table name
December 31, 2013 at 1:47 pm
Thanks both for quick reply. Big thanks to Nevin. It worked.
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply