SQL - ALTER CLASS

Updates attributes on an existing class in the schema.

Syntax

ALTER CLASS <class> <attribute-name> <attribute-value>
  • <class> Defines the class you want to change.
  • <attribute-name> Defines the attribute you want to change. For a list of supported attributes, see the table below.
  • <attribute-value> Defines the value you want to set.
  • UNSAFE Allows for the processing of a modification on an Edge class, without an exception error. The alteration will not take into account edge connections nor indexing. It is not recommended to use this! Be sure to make a backup before running it.

Examples

  • Define a super-class:

    orientdb> ALTER CLASS Employee SUPERCLASS Person
    
  • Define multiple inheritances:

    orientdb> ALTER CLASS Employee SUPERCLASS Person, `ORestricted`
    

    This feature was introduced in version 2.1.

  • Add a super-class:

    orientdb> ALTER CLASS Employee SUPERCLASS +Person
    

    This feature was introduced in version 2.1.

  • Remove a super-class:

    orientdb> ALTER CLASS Employee SUPERCLASS -Person
    

    This feature was introduced in version 2.1.

  • Update the class name from Account to Seller:

    orientdb> ALTER CLASS Account NAME Seller
    
  • Update the oversize factor on the class Account:

    orientdb> ALTER CLASS Account OVERSIZE 2
    
  • Add a cluster to the class Account.

    orientdb> ALTER CLASS Account ADDCLUSTER account2
    

    In the event that the cluster does not exist, it automatically creates it.

  • Remove a cluster from the class Account with the ID 34:

    orientdb> ALTER CLASS Account REMOVECLUSTER 34
    
  • Add custom properties:

    orientdb> ALTER CLASS Post CUSTOM `onCreate.fields`="_allowRead,_allowUpdate"
    orientdb> ALTER CLASS Post CUSTOM `onCreate.identityType`="role"
    
  • Create a new cluster for the class Employee, then set the cluster selection strategy to balanced:

    orientdb> CREATE CLUSTER employee_1
    orientdb> ALTER CLASS Employee ADDCLUSTER employee_1
    orientdb> ALTER CLASS Employee CLUSTERSELECTION balanced
    
  • Convert the class TheClass to an abstract class:

    orientdb> ALTER CLASS TheClass ABSTRACT true
    

For more information see CREATE CLASS, DROP CLASS, ALTER CLUSTER commands.
For more information on other commands, please refer to Console Commands and SQL Commands.

Supported Attributes

AttributeTypeSupportDescription
NAMEIdentifierChanges the class name.
SHORTNAMEIdentifierDefines a short name, (that is, an alias), for the class. Use NULL to remove a short name assignment.
SUPERCLASSIdentifierDefines a super-class for the class. Use NULL to remove a super-class assignment. Beginning with version 2.1, it supports multiple inheritances. To add a new class, you can use the syntax +<class>, to remove it use -<class>.
SUPERCLASSESIdentifier [, Identifier]*Defines a super-classes for the class. Beginning with version 2.1, it supports multiple inheritances. To add a new class, you can use the syntax +<class>, to remove it use -<class>.
OVERSIZEDecimal numberDefines the oversize factor.
ADDCLUSTERIdentifier or IntegerAdds a cluster to the class. If the cluster doesn't exist, it creates a physical cluster. Adding clusters to a class is also useful in storing records in distributed servers. For more information, see Distributed Sharding.
REMOVECLUSTERIdentifier or IntegerRemoves a cluster from a class. It does not delete the cluster, only removes it from the class.
STRICTMODEBooleanEnalbes or disables strict mode. When in strict mode, you work in schema-full mode and cannot add new properties to a record if they're part of the class' schema definition.
CLUSTERSELECTION1.7Defines the selection strategy in choosing which cluster it uses for new records. On class creation it inherits the setting from the database. For more information, see Cluster Selection.
CUSTOMDefines custom properties. Property names and values must follow the syntax <property-name>=<value> without spaces between the name and value. The attribute name is an indentifier, so it has to be back-tick quoted if it contains special characters (eg. dots); the value is a string, so it has to be quoted with single or double quotes.
ABSTRACTBooleanConverts class to an abstract class or the opposite.

History

2.1

  • Added support for multiple inheritance.

1.7

  • Added support for CLUSTERSELECTION that sets the strategy used on selecting the cluster to use when creating new records.