Neo4j 简明教程

Neo4j - Drop Unique

我们在前一章中已经讨论了使用示例创建 UNIQUE 约束操作。在本章中,我们将讨论删除 UNIQUE 约束操作并提供示例。

We have already discussed creating UNIQUE constraint operations with examples in the previous chapter. In this chapter, we will discuss dropping UNIQUE constraint operation with examples.

Neo4j CQL 提供“DROP CONSTRAINT”命令,用于从节点或关系属性中删除现有的 Unique 约束。

Neo4j CQL provides "DROP CONSTRAINT" command to delete existing Unique constraint from a node or relationship property.

Syntax

以下是 Neo4j 中删除 UNIQUE 约束的语法。

Following is the syntax for dropping a UNIQUE constraint in Neo4j.

DROP CONSTRAINT ON (node:label)
ASSERT node.id IS UNIQUE

Example

以下是删除属性 id 上的 UNIQUE 约束的 Cypher 查询示例。

Following is a sample Cypher Query to remove the UNIQUE constraint on the property id.

DROP CONSTRAINT ON (n:player)
ASSERT n.id IS UNIQUE

执行上述查询,执行以下步骤:

To execute the above query, carry out the following steps −

Step 1 - 打开 Neo4j Desktop App 并启动 Neo4j Server。使用 URL http://localhost:7474/ 打开 Neo4j 的内置浏览器应用,如下面的屏幕截图所示。

Step 1 − Open the Neo4j desktop App and start the Neo4j Server. Open the built-in browser app of Neo4j using the URL http://localhost:7474/ as shown in the following screenshot.

browser app

Step 2 - 在美元提示符中复制并粘贴所需的查询,并按播放按钮(执行查询)突出显示在下面的屏幕截图中。

Step 2 − Copy and paste the desired query in the dollar prompt and press the play button (to execute the query) highlighted in the following screenshot.

drop constraint

Result

执行后,您将获得以下结果。

On executing, you will get the following result.

removed constraint