Orientdb 简明教程
OrientDB - Update Record
Update Record 命令用来修改某个特定记录的值。SET 是更新某个特定字段值的基本命令。
Update Record command is used to modify the value of a particular record. SET is the basic command to update a particular field value.
以下语句是更新命令的基本语法。
The following statement is the basic syntax of the Update command.
UPDATE <class>|cluster:<cluster>|<recordID>
[SET|INCREMENT|ADD|REMOVE|PUT <field-name> = <field-value>[,]*] |[CONTENT| MERGE <JSON>]
[UPSERT]
[RETURN <returning> [<returning-expression>]]
[WHERE <conditions>]
[LOCK default|record]
[LIMIT <max-records>] [TIMEOUT <timeout>]
以下是上文中选项的详细信息。
Following are the details about the options in the above syntax.
SET - 定义要更新的字段。
SET − Defines the field to update.
INCREMENT - 通过给定值递增指定字段值。
INCREMENT − Increments the specified field value by the given value.
ADD - 在集合字段中添加新项。
ADD − Adds the new item in the collection fields.
REMOVE - 从集合字段中移除一项。
REMOVE − Removes an item from the collection field.
PUT - 向映射字段中输入一项。
PUT − Puts an entry into map field.
CONTENT - 用 JSON 文档内容替换记录内容。
CONTENT − Replaces the record content with JSON document content.
MERGE - 用 JSON 文档合并记录内容。
MERGE − Merges the record content with a JSON document.
LOCK - 指定如何在加载和更新之间锁定记录。我们有两个选项来指定 Default 和 Record 。
LOCK − Specifies how to lock the records between load and update. We have two options to specify Default and Record.
UPSERT - 如果记录存在则更新,如果不存在则插入新记录。它有助于执行单个查询来代替执行两个查询。
UPSERT − Updates a record if it exists or inserts a new record if it doesn’t. It helps in executing a single query in the place of executing two queries.
RETURN − 指定要在记录数量中返回的表达式。
RETURN − Specifies an expression to return instead of the number of records.
LIMIT − 定义要更新的最大记录数量。
LIMIT − Defines the maximum number of records to update.
TIMEOUT − 定义在超时前允许更新运行的时间。
TIMEOUT − Defines the time you want to allow the update run before it times out.
Example
让我们考虑我们在上一章中使用的相同的客户表。
Let us consider the same Customer table that we have used in the previous chapter.
Sr.No. |
Name |
Age |
1 |
Satish |
25 |
2 |
Krishna |
26 |
3 |
Kiran |
29 |
4 |
Javeed |
21 |
5 |
Raja |
29 |
尝试使用以下查询以更新名为“Raja”的客户的年龄。
Try the following query to update the age of a customer ‘Raja’.
Orientdb {db = demo}> UPDATE Customer SET age = 28 WHERE name = 'Raja'
如果成功执行了以上查询,您会获得以下输出。
If the above query is executed successfully, you will get the following output.
Updated 1 record(s) in 0.008000 sec(s).
要检查客户表中的记录,可以使用以下查询。
To check the record of Customer table you can use the following query.
orientdb {db = demo}> SELECT FROM Customer
如果成功执行了以上查询,您会获得以下输出。
If the above query is executed successfully, you will get the following output.
----+-----+--------+----+-------+----
# |@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 |28
----+-----+--------+----+-------+----