如何在 neo4j 中对两个属性创建唯一约束?
how do I create unique constraints on two properties in neo4j?
我使用节点作为中间路径元素,但我想确保 start/end 是唯一的。如何创建需要检查两个值的约束?
我可以单独设置,但看不到两部分约束的语法。
neolib.run_query(
"""CREATE CONSTRAINT
uSource
if not exists
ON (m:route) ASSERT m.source IS UNIQUE""")
neolib.run_query(
"""CREATE CONSTRAINT
uTarget
if not exists
ON (m:route) ASSERT m.target IS UNIQUE""")
它有这个文档:
https://neo4j.com/docs/cypher-manual/current/administration/constraints/#query-constraint-node-key
CREATE CONSTRAINT [constraint_name] [IF NOT EXISTS]
ON (n:LabelName)
ASSERT (n.propertyName_1,
n.propertyName_2,
…
n.propertyName_n)
IS NODE KEY
[OPTIONS "{" option: value[, ...] "}"]
FOR EXAMPLE:
CREATE CONSTRAINT uSourceTarget IF NOT EXISTS ON (m:route) ASSERT (m.source, m. target) IS NODE KEY
注意:仅适用于企业版(不适用于社区版)
我使用节点作为中间路径元素,但我想确保 start/end 是唯一的。如何创建需要检查两个值的约束?
我可以单独设置,但看不到两部分约束的语法。
neolib.run_query(
"""CREATE CONSTRAINT
uSource
if not exists
ON (m:route) ASSERT m.source IS UNIQUE""")
neolib.run_query(
"""CREATE CONSTRAINT
uTarget
if not exists
ON (m:route) ASSERT m.target IS UNIQUE""")
它有这个文档:
https://neo4j.com/docs/cypher-manual/current/administration/constraints/#query-constraint-node-key
CREATE CONSTRAINT [constraint_name] [IF NOT EXISTS]
ON (n:LabelName)
ASSERT (n.propertyName_1,
n.propertyName_2,
…
n.propertyName_n)
IS NODE KEY
[OPTIONS "{" option: value[, ...] "}"]
FOR EXAMPLE:
CREATE CONSTRAINT uSourceTarget IF NOT EXISTS ON (m:route) ASSERT (m.source, m. target) IS NODE KEY
注意:仅适用于企业版(不适用于社区版)