OrientDB is a NoSQL data set that can store the archives and diagram situated information. NoSQL information base doesn't contain any table, so how might you embed information as a record. Here you can see the table information as class, property, vertex, and edge significance classes resemble tables, and properties resemble documents in the tables.
We can characterize every one of these substances utilizing pattern in OrientDB. Property information can be embedded into a class. Addition order makes another record in the information base composition. Records can be diagram less or adhere to some predefined rules.
The accompanying assertion is the essential grammar of the Insert Record order.
INSERT INTO [class:]<class>|cluster:<cluster>|index:<index>
[(<field>[,]*) VALUES (<expression>[,]*)[,]*]|
[SET <field> = <expression>|<sub-command>[,]*]|
[CONTENT {<JSON>}]
[RETURN <expression>]
[FROM <query>]
Following are the insights concerning the alternatives in the above language structure.
SET − Defines each field alongside the worth.
CONTENT − Defines JSON information to set field esteems. This is discretionary.
RETURN − Defines the articulation to return rather than number of records embedded. The most well-known use cases are −
- @rid − Returns the Record ID of the new record.
- @this − Returns the whole new record.
FROM − Where you need to embed the record or an outcome set.
Example
Allow us to consider a Customer table with the accompanying fields and types.
Sr.No. | Field Name | Type |
---|---|---|
1 | Id | Integer |
2 | Name | String |
3 | Age | Integer |
You can make the Schema (table) by executing the accompanying orders.
CREATE DATABASE PLOCAL:/opt/orientdb/databases/sales
CREATE CLASS Customer
CREATE PROPERTY Customer.id integer
CREATE PROPERTY Customer.name String
CREATE PROPERTY Customer.age integer
In the wake of executing all the orders, you will get the table name Customer with id, name, and age fields. You can check the table by executing select question into the Customer table.
OrientDB gives various approaches to embed a record. Consider the accompanying Customer table containing the example records.
Sr.No. | Name | Age |
---|---|---|
1 | Satish | 25 |
2 | Krishna | 26 |
3 | Kiran | 29 |
4 | Javeed | 21 |
5 | Raja | 29 |
The accompanying order is to embed the initial record into the Customer table.
INSERT INTO Customer (id, name, age) VALUES (01,'satish', 25
In the event that the above order is effectively executed, you will get the accompanying yield.
Inserted record 'Customer#11:0{id:1,name:satish,age:25} v1' in 0.069000 sec(s).
The accompanying order is to embed the second record into the Customer table.
INSERT INTO Customer SET id = 02, name = 'krishna', age = 26
In the event that the above order is effectively executed, you will get the accompanying yield.
Inserted record 'Customer#11:1{id:2,age:26,name:krishna} v1' in 0.005000 sec(s).
The accompanying order is to embed the third record into the Customer table.
INSERT INTO Customer CONTENT {"id": "03", "name": "kiran", "age": "29"}
On the off chance that the above order is effectively executed, you will get the accompanying yield.
Inserted record 'Customer#11:2{id:3,name:kiran,age:29} v1' in 0.004000 sec(s).
The accompanying order is to embed the following two records into the Customer table.
INSERT INTO Customer (id, name, age) VALUES (04,'javeed', 21), (05,'raja', 29)
On the off chance that the above order is effectively executed, you will get the accompanying yield.
Inserted record '[Customer#11:3{id:4,name:javeed,age:21} v1,
Customer#11:4{id:5,name:raja,age:29} v1]' in 0.007000 sec(s).
You can check if every one of these records are embedded or not by executing the accompanying order.
SELECT FROM Customer
On the off chance that the above order is effectively executed, you will get the accompanying yield.
----+-----+--------+----+-------+----
# |@RID |@CLASS |id |name |age
----+-----+--------+----+-------+----
0 |#11:0|Customer|1 |satish |25
1 |#11:1|Customer|2 |krishna|26
2 |#11:2|Customer|3 |kiran |29
3 |#11:3|Customer|4 |javeed |21
4 |#11:4|Customer|5 |raja |29
----+-----+--------+----+-------+----