SQL - CREATE PROPERTY
Creates a new property in the schema. It requires that the class for the property already exist on the database.
Syntax
CREATE PROPERTY
<class>.<property>
[IF NOT EXISTS]
<type>
[<link-type>|<link-class>]
( <property constraint> [, <property-constraint>]* )
[UNSAFE]
<class>
Defines the class for the new property.IF NOT EXISTS
(since v 2.2.13) Creates the property only if it does not exist. If it does, the statement just does nothing.<property>
Defines the logical name for the property.<type>
Defines the property data type. For supported types, see the table below.<link-type>
Defines the contained type for container property data types. For supported link types, see the table below.<link-class>
Defines the contained class for container property data types. For supported link types, see the table below.<property-constraint>
SeeALTER PROPERTY
<attribute-name> [ <attribute-value> ]
(since V2.2.3)UNSAFE
Defines whether it checks existing records. On larger databases, with millions of records, this could take a great deal of time. Skip the check when you are sure the property is new. Introduced in version 2.0.
When you create a property, OrientDB checks the data for property and type. In the event that persistent data contains incompatible values for the specified type, the property creation fails. It applies no other constraints on the persistent data.
Examples
Create the property
name
of the string type in the classUser
:orientdb>
CREATE PROPERTY User.name STRING
Create a property formed from a list of strings called
tags
in the classProfile
:orientdb>
CREATE PROPERTY Profile.tags EMBEDDEDLIST STRING
Create the property
friends
, as an embedded map in a circular reference:orientdb>
CREATE PROPERTY Profile.friends EMBEDDEDMAP Profile
Create the property
name
of the string type in the classUser
, mandatory, with minimum and maximum length (since V2.2.3):orientdb>
CREATE PROPERTY User.name STRING (MANDATORY TRUE, MIN 5, MAX 25)
For more information, see
Supported Types
OrientDB supports the following data types for standard properties:
BOOLEAN |
SHORT |
DATE |
DATETIME |
BYTE |
INTEGER |
LONG |
STRING |
LINK |
DECIMAL |
DOUBLE |
FLOAT |
BINARY |
EMBEDDED |
LINKBAG |
It supports the following data types for container properties.
EMBEDDEDLIST |
EMBEDDEDSET |
EMBEDDEDMAP |
LINKLIST |
LINKSET |
LINKMAP |
For these data types, you can optionally define the contained type and class. The supported link types are the same as the standard property data types above.