Orientdb 简明教程

OrientDB - Alter Class

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.

以下语句是 Alter Class 命令的基本语法。

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> − 定义类名。

<class> − Defines the class name.

<attribute-name> − 定义您想要更改的属性。

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

<attribute-value> − 定义想要为该属性设置的值。

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

下表定义了支持 Alter Class 命令的属性列表。

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

Attribute

Type

Description

NAME

String

Changes the class name.

SHORTNAME

String

Defines a short name, (that is, an alias), for the class. Use NULL to remove a short name assignment.

SUPERCLASS

String

Defines a super-class for the class. To add a new class, you can use the syntax +<class>, to remove it use -<class>.

OVERSIZE

Decimal number

Defines the oversize factor.

ADDCLUSTER

String

Adds 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.

REMOVECLUSTER

String

Removes a cluster from a class. It does not delete the cluster, only removes it from the class.

STRICTMODE

-

Enables 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.

CLUSTERSELECTION

-

Defines the selection strategy in choosing which cluster it uses for new records.

CUSTOM

-

Defines custom properties. Property names and values must follow the syntax <propertyname>=<value> without spaces between the name and value.

ABSTRACT

Boolean

Converts 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.

以下查询用于为现有类“Employee”定义超类“Person”。

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

以下查询用于为现有类“Employee”添加超类“Person”。

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