64924

Whats wrong with sp_rename with column?

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.

Recommend

  • XSL stylesheet: creating Hyperlink based of query item_id
  • Diagnosing chrome.usb.claimInterface() error
  • Repeat a block of code a fixed number of times
  • Errors with installing Prism in visual studio
  • Asynchronous issue with OBJLoader - wait for XHR to finish loading
  • suppress django naive datetime warnings
  • Is it possible to pass a block of code as a macro argument?
  • Write XML string directly to XML file with VBScript
  • Pandas error: Can only use .str accessor with string values, which use np.object_ dtype in pandas
  • Get indices of array where two conditions (on different arrays) are true
  • Selecting TOP 4 records from multiple SQL Server tables. Using vb.net
  • Lync Database - Mobile vs PC users
  • Pass pointer array to function
  • Measure heap used by each object in Java [closed]
  • Migrating from java 1.4 ,EJB 1 to Java 6 and EJB 3 [closed]
  • Price range slider for my website
  • How can I merge my files when the folder structure has changed using Borland StarTeam?
  • htaccess settings for angularJS pushstate
  • Microsoft Chart Controls for Microsoft .NET Framework 4.0
  • How to give custom name to Sqoop output files
  • What is RSL (Runtime shared library ) used for in flash?
  • Iterate twice through a DataReader
  • INSERT EXEC Statement cannot be nested [duplicate]
  • Prolog Ambiguous Output
  • Get used tables from sql query [duplicate]
  • Redshift Querying: error xx000 disk full redshift
  • pillow imaging ImportError
  • Needing to do .toArray() to get output of mongodb .find() on key name not value
  • Rails Find when some params will be blank
  • Meteor: Do Something On Email Verification Confirmation
  • Deselecting radio buttons while keeping the View Model in synch
  • How do I fake an specific browser client when using Java's Net library?
  • How reduce the height of an mschart by breaking up the y-axis
  • Perl system calls when running as another user using sudo
  • Where to put my custom functions in Wordpress?
  • Symfony2: How to get request parameter
  • ORA-29908: missing primary invocation for ancillary operator
  • How can I estimate amount of memory left with calling System.gc()?
  • RestKit - RKRequestDelegate does not exist
  • WPF Applying a trigger on binding failure