...or using a stored procedure along these lines:

ClassMethod RenameTable(oldName As %String, newName As %String) As %String [ SqlProc ]
{
   try {
      &sql(select %ID into :className
         from %Dictionary.ClassDefinition
         where SqlTableName = :oldName
      )
      if SQLCODE set status = "Error: Table '" _ oldName _ "' not found." quit

      set classDef = ##class(%Dictionary.ClassDefinition).%OpenId(className)
      set classDef.SqlTableName = newName
      set saveStatus = classDef.%Save()
      set status = $case(saveStatus, 1: "OK", : "Error: " _ $system.Status.GetErrorText(saveStatus))
   } catch {
      set status = "Error: " _ $zerror
   }
   return status
}

Note: This doesn't handle the special case where there is no 'SqlTableName' defined.

Hi Kishan,

The error message indicates that you're trying to access a property called 'value' in a collection of objects (%Collection.ListOfObj), but there is no such thing. My guess is that you're trying to access a property of one of the objects in the collection, in which case you need to use the 'GetAt' method of the collection object to specify which one you're after.

Here's more information on how to handle collections of objects.

Otto

This only matters for very long loops (and you'd need a pretty extreme scenario for it to matter even then), but a post-conditional 'quit' is only meaningful if there's more code after it, and it comes with a performance cost, so this line:

USER>for count = count:1 set ref=$query(@ref) quit:ref=""

...should be:

USER>for count = count:1 set ref=$query(@ref) if (ref="") quit