Skip to content

Commit 06ce296

Browse files
second batch
1 parent 1edaa6d commit 06ce296

File tree

1 file changed

+118
-68
lines changed

1 file changed

+118
-68
lines changed

modules/ROOT/pages/constraints/managing-constraints.adoc

Lines changed: 118 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ It will be updated to say `Node property uniqueness constraints added: 1` in a f
7777
.Create a relationship property uniqueness constraint on a single property label:new[Introduced in 5.7]
7878
======
7979
80-
A relationship property uniqueness constraint ensures that certain relationships have a set of specified properties whose combined value is unique when all properties exist on the relationship.
81-
8280
.Create a constraint requiring `SEQUEL_OF` relationships to have unique `order` properties
8381
[source, cypher]
8482
----
@@ -212,8 +210,6 @@ It is not possible to create composite existence constraints on several properti
212210
.Create a node property existence constraint
213211
======
214212
215-
A node property existence constraint ensures that certain nodes have a specified property.
216-
217213
.Create a constraint requiring `Author` nodes to have a `name` property
218214
[source, cypher]
219215
----
@@ -233,8 +229,6 @@ Added 1 constraint.
233229
.Create a relationship property existence constraint
234230
======
235231
236-
A relationship property existence constraint ensures that certain relationships have a certain property.
237-
238232
.Create a constraint requiring `WROTE` relationships to have a `year` property
239233
[source, cypher]
240234
----
@@ -321,8 +315,6 @@ It is not possible to create composite property type constraints on several prop
321315
.Create a node property type constraint
322316
======
323317
324-
A node property existence constraint ensures that certain nodes have a specified property.
325-
326318
.Create a constraint requiring `title` properties on `Movie` nodes to be of type `STRING`
327319
[source, cypher]
328320
----
@@ -331,7 +323,7 @@ FOR (movie:Movie) REQUIRE movie.title IS :: STRING
331323
----
332324
333325
.Result
334-
[queryresult]
326+
[source, queryresult]
335327
----
336328
Added 1 constraint.
337329
----
@@ -340,8 +332,6 @@ Added 1 constraint.
340332
.Create a relationship property type constraint
341333
======
342334
343-
A relationship property existence constraint ensures that certain relationships have a certain property.
344-
345335
.Create a constraint requiring `order` properties on `PART_OF` relationships to be of type `INTEGER`
346336
[source, cypher]
347337
----
@@ -505,8 +495,6 @@ For the full command syntax to create a key constraint, see xref:constraints/syn
505495
.Create a node key constraint on a single property
506496
======
507497
508-
A node key constraint ensures that certain nodes have a set of specified properties whose combined value is unique and all properties in the set are present.
509-
510498
.Create a constraint requiring `Director` nodes to have a unique `imdbId` property as a node key.
511499
[source, cypher]
512500
----
@@ -526,9 +514,6 @@ Added 1 constraint.
526514
.Create a relationship key constraint on a single property label:new[Introduced in 5.7]
527515
======
528516
529-
A relationship key constraint ensures that certain relationships have a set of defined properties whose combined value is unique.
530-
It also ensures that all properties in the set are present.
531-
532517
.Create a constraint requiring `OWNS` relationships to have a unique `ownershipId` property as a relationship key
533518
[source, cypher]
534519
----
@@ -578,9 +563,6 @@ Added 1 constraint.
578563
.Create a composite relationship key constraint label on multiple properties label:new[Introduced in 5.7]
579564
======
580565
581-
A relationship key constraint ensures that certain relationships have a set of defined properties whose combined value is unique.
582-
It also ensures that all properties in the set are present.
583-
584566
.Create a constraint requiring `KNOWS` relationships to have a unique combination of `since` and `how` properties as a relationship key
585567
[source, cypher]
586568
----
@@ -636,6 +618,7 @@ Added 2 labels, created 2 nodes, set 6 properties, created 1 relationship.
636618

637619

638620
[role=label--new-5.16]
621+
[[create-constraint-with-parameter]]
639622
=== Create a constraint with a parameter
640623

641624
All constraint types can be created with a parameterized name.
@@ -692,7 +675,7 @@ Added 1 constraint.
692675
693676
======
694677

695-
[[multiple-constrains]]
678+
[[multiple-constraints-on-same-property-combinations]]
696679
=== Multiple constraints on the same property combinations
697680

698681
Some constraint types are allowed on the same label/relationship type and property combination.
@@ -838,11 +821,17 @@ There are no valid index configuration values for the constraint-backing range i
838821
=== Handling existing constraints when creating a constraint
839822

840823
Creating an already existing constraint will fail.
824+
This includes:
825+
826+
* Creating a constraint identical to a constraint already in the database.
827+
* Creating a constraint with a different name but on the same schema as a constraint already in the database.
828+
* Creating a constraint with the same name but on a different schema as a constraint already in the database.
829+
841830
To avoid such an error, `IF NOT EXISTS` can be added to the `CREATE` command.
842831
This will ensure that no error is thrown and that no constraint is created if any other constraint with the given name, or another constraint on the same constraint type and schema, or both, already exists.
843832
As of Neo4j 5.17, an informational notification is instead returned showing the existing constraint which blocks the creation.
844833

845-
.Create a relationship property uniqueness constraint when a constraint with the same name exists
834+
.Create a relationship property uniqueness constraint when an identical constraint already exists
846835
======
847836
848837
.Create a constraint requiring all `SEQUEL_OF` relationships to have unique `order` properties
@@ -864,85 +853,78 @@ Because the same constraint already exists, nothing will happen:
864853
[source]
865854
----
866855
`CREATE CONSTRAINT sequels IF NOT EXISTS FOR ()-[e:SEQUEL_OF]-() REQUIRE (e.order) IS UNIQUE` has no effect.
867-
`CONSTRAINT sequels FOR ()-[e:SEQUEL_OF]-() REQUIRE (e.order, e.seriesTitle) IS UNIQUE` already exists.
856+
`CONSTRAINT sequels FOR ()-[e:SEQUEL_OF]-() REQUIRE (e.order) IS UNIQUE` already exists.
868857
----
869858
870859
======
871860

872861

873-
[[constraint-creation-failures-and-data-violations]]
874-
=== Constraint creation failures and data violation scenarios
875-
876-
* xref:constraints/managing-constraints.adoc#create-an-already-existing-constraint[]
877-
* xref:constraints/managing-constraints.adoc#create-data-that-violates-a-constraint[]
878-
* xref:constraints/managing-constraints.adoc#fail-to-create-constraint-due-to-existing-data[]
879-
* xref:constraints/managing-constraints.adoc#removing-an-existing-constrained-property-will-fail[]
880-
* xref:constraints/managing-constraints.adoc#create-key-and-uniqueness-constraint-on-same-schema-as-existing-index[]
881-
882-
883-
[[create-an-already-existing-constraint]]
884-
==== Creating an already existing constraint will fail
885-
886-
Creating a constraint on a node label or relationship property that is already constrained will fail.
887-
This applies to all constraint types.
888-
889-
.Create an already existing node property uniqueness constraint
862+
.Create a relationship property uniqueness constraint when the same constraint with a different name already exists
890863
======
891864
892-
////
893-
[source, cypher, role=test-setup]
865+
.Create a constraint requiring all `SEQUEL_OF` relationships to have unique `order` properties
866+
[source, cypher]
894867
----
895-
CREATE CONSTRAINT preExisting_book_published FOR (book:Book) REQUIRE book.published IS UNIQUE
868+
CREATE CONSTRAINT new_sequels IF NOT EXISTS
869+
FOR ()-[sequel:SEQUEL_OF]-() REQUIRE sequel.order IS UNIQUE
896870
----
897-
////
898871
899-
.Create a constraint requiring `Book` nodes to have unique `published` properties, when that constraint already exists
900-
[source, cypher, role=test-fail]
872+
Because a constraint with a different name (`sequels`) on the same schema exists, nothing will happen:
873+
874+
.Result
875+
[source, queryresult]
901876
----
902-
CREATE CONSTRAINT book_published FOR (book:Book) REQUIRE book.published IS UNIQUE
877+
(no changes, no records)
903878
----
904879
905-
In this case, the constraint cannot be created because it already exists.
906-
907-
.Error message
908-
[source, error]
880+
.Notification
881+
[source]
909882
----
910-
Constraint already exists:
911-
Constraint( id=4, name='preExisting_book_published', type='UNIQUENESS', schema=(:Book {published}), ownedIndex=3 )
883+
`CREATE CONSTRAINT sequels IF NOT EXISTS FOR ()-[e:SEQUEL_OF]-() REQUIRE (e.order) IS UNIQUE` has no effect.
884+
`CONSTRAINT sequels FOR ()-[e:SEQUEL_OF]-() REQUIRE (e.order) IS UNIQUE` already exists.
912885
----
913886
914-
[NOTE]
915-
The constraint type will be updated to say `NODE PROPERTY UNIQUENESS` in a future version of Neo4j.
916-
917887
======
918888

919-
.Create an already existing relationship property type constraint
889+
.Create a relationship property uniqueness constraint with the same name as a different type of constraint already in the graph
920890
======
921891
892+
.Create a constraint requiring all `AUTHORED` relationships to have unique `name` properties
922893
923-
.Create a constraint requiring `order` properties on `PART_OF` relationships to be of type `INTEGER`, when that constraint already exists
924-
[source, cypher, role=test-fail]
894+
[source, cypher]
925895
----
926-
CREATE CONSTRAINT belongs_to
927-
FOR ()-[part:PART_OF]-() REQUIRE part.order :: INTEGER
896+
CREATE CONSTRAINT author_name IF NOT EXISTS
897+
FOR ()-[a:AUTHORED]-() REQUIRE a.name IS UNIQUE
928898
----
929899
930-
In this case, the constraint cannot be created because it already exists (but with a different name).
900+
Because a node property existence constraint named `author_name` already exists, nothing will happen:
931901
932-
.Error message
933-
[source, error]
902+
.Result
903+
[source, queryresult]
934904
----
935-
Constraint already exists: Constraint( id=24, name='part_of', type='RELATIONSHIP PROPERTY TYPE', schema=()-[:PART_OF {order}]-(), propertyType=INTEGER )
905+
(no changes, no records)
906+
----
907+
908+
.Notification
909+
[source]
910+
----
911+
`CREATE CONSTRAINT author_name IF NOT EXISTS FOR ()-[e:AUTHORED]-() REQUIRE (e.name) IS UNIQUE` has no effect.
912+
`CONSTRAINT author_name FOR (e:Author) REQUIRE (e.name) IS NOT NULL` already exists.
936913
----
937914
938915
======
939916

917+
[[constraints-and-data-violation-scenarios]]
918+
=== Constraints and data violation scenarios
919+
920+
* xref:constraints/managing-constraints.adoc#create-data-that-violates-a-constraint[]
921+
* xref:constraints/managing-constraints.adoc#removing-an-existing-constrained-property-will-fail[]
922+
* xref:constraints/managing-constraints.adoc#fail-to-create-constraint-due-to-existing-data[]
923+
940924

941925
[[create-data-that-violates-a-constraint]]
942926
==== Creating data that violates existing constraints will fail
943927

944-
This applies to all constraint types.
945-
946928
.Create a node that violates an existing node property uniqueness constraint
947929
======
948930
@@ -1022,11 +1004,79 @@ Node(0) with label `Actor` must have the properties (`firstname`, `surname`)
10221004
10231005
======
10241006

1007+
1008+
[[constraint-creation-failures]]
1009+
=== Constraint creation failures
1010+
1011+
* xref:constraints/managing-constraints.adoc#create-an-already-existing-constraint[]
1012+
* xref:constraints/managing-constraints.adoc#fail-to-create-constraint-due-to-existing-data[]
1013+
* xref:constraints/managing-constraints.adoc#create-key-and-uniqueness-constraint-on-same-schema-as-existing-index[]
1014+
1015+
1016+
[[create-an-already-existing-constraint]]
1017+
==== Creating an already existing constraint will fail
1018+
1019+
Creating an already existing constraint
1020+
1021+
Creating a constraint on the same label or relationship type and properties that is already constrained will fail.
1022+
1023+
.Create an already existing node property uniqueness constraint
1024+
======
1025+
1026+
////
1027+
[source, cypher, role=test-setup]
1028+
----
1029+
CREATE CONSTRAINT preExisting_book_published FOR (book:Book) REQUIRE book.published IS UNIQUE
1030+
----
1031+
////
1032+
1033+
.Create a constraint requiring `Book` nodes to have unique `published` properties, when that constraint already exists
1034+
[source, cypher, role=test-fail]
1035+
----
1036+
CREATE CONSTRAINT book_published FOR (book:Book) REQUIRE book.published IS UNIQUE
1037+
----
1038+
1039+
In this case, the constraint cannot be created because it already exists.
1040+
1041+
.Error message
1042+
[source, error]
1043+
----
1044+
Constraint already exists:
1045+
Constraint( id=4, name='preExisting_book_published', type='UNIQUENESS', schema=(:Book {published}), ownedIndex=3 )
1046+
----
1047+
1048+
[NOTE]
1049+
The constraint type will be updated to say `NODE PROPERTY UNIQUENESS` in a future version of Neo4j.
1050+
1051+
======
1052+
1053+
.Create an already existing relationship property type constraint
1054+
======
1055+
1056+
1057+
.Create a constraint requiring `order` properties on `PART_OF` relationships to be of type `INTEGER`, when that constraint already exists
1058+
[source, cypher, role=test-fail]
1059+
----
1060+
CREATE CONSTRAINT belongs_to
1061+
FOR ()-[part:PART_OF]-() REQUIRE part.order :: INTEGER
1062+
----
1063+
1064+
In this case, the constraint cannot be created because it already exists (but with a different name).
1065+
1066+
.Error message
1067+
[source, error]
1068+
----
1069+
Constraint already exists: Constraint( id=24, name='part_of', type='RELATIONSHIP PROPERTY TYPE', schema=()-[:PART_OF {order}]-(), propertyType=INTEGER )
1070+
----
1071+
1072+
======
1073+
1074+
1075+
1076+
10251077
[[fail-to-create-constraint-due-to-existing-data]]
10261078
==== Creating constraints when there exists conflicting data will fail
10271079

1028-
This applies to all constraint types.
1029-
10301080
.Create a node property uniqueness constraint when conflicting nodes exist
10311081
======
10321082

0 commit comments

Comments
 (0)