OrientDB – Alter Class

Class and Property in OrientDB are used to build a schema with the respective attributes such as class name, super-class, cluster, number of clusters, Abstract, etc. If you want to modify or update any attribute of existing classes in the schema then you have to use Alter Class command.

The following statement is the basic syntax of the Alter Class Command.

ALTER CLASS <class> <attribute-name> <attribute-value> 

Following are the details about the options in the above syntax.

<class> − Defines the class name.

<attribute-name> − Defines the attribute you want to change.

<attribute-value> − Defines the value you want to set for the attribute.

The following table defines the list of attributes that support Alter Class command.

AttributeTypeDescription
NAMEStringChanges the class name.
SHORTNAMEStringDefines a short name, (that is, an alias), for the class. Use NULL to remove a short name assignment.
SUPERCLASSStringDefines a super-class for the class. To add a new class, you can use the syntax +<class>, to remove it use -<class>.
OVERSIZEDecimal numberDefines the oversize factor.
ADDCLUSTERStringAdds 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.
REMOVECLUSTERStringRemoves a cluster from a class. It does not delete the cluster, only removes it from the class.
STRICTMODEEnables or disables strict mode. When in strict mode, you work in schema-full mode and cannot add new properties to a record if they are part of the class’ schema definition.
CLUSTERSELECTIONDefines the selection strategy in choosing which cluster it uses for new records.
CUSTOMDefines custom properties. Property names and values must follow the syntax <propertyname>=<value> without spaces between the name and value.
ABSTRACTBooleanConverts class to an abstract class or the opposite.

Example

Let us try few examples that will update or modify the attributes of the existing class.

The following query is used to define a super-class ‘Person’ for an existing class ‘Employee’.

orientdb> ALTER CLASS Employee SUPERCLASS Person

If the above query is executed successfully, you will get the following output.

Class altered successfully

The following query is used to add a super-class ‘Person’ for an existing class ‘Employee’.

orientdb> ALTER CLASS Employee SUPERCLASS +Person 

If the above query is executed successfully, you will get the following output.

Class altered successfully 

Leave a Reply