diff --git a/modules/ROOT/content-nav.adoc b/modules/ROOT/content-nav.adoc index b023bfad4..d1356084c 100644 --- a/modules/ROOT/content-nav.adoc +++ b/modules/ROOT/content-nav.adoc @@ -110,7 +110,9 @@ ** xref:indexes/syntax.adoc[] * xref:constraints/index.adoc[] -** xref:constraints/managing-constraints.adoc[] +** xref:constraints/create-constraints.adoc[] +** xref:constraints/list-constraints.adoc[] +** xref:constraints/drop-constraints.adoc[] ** xref:constraints/syntax.adoc[] * xref:planning-and-tuning/index.adoc[] diff --git a/modules/ROOT/pages/appendix/gql-conformance/additional-cypher.adoc b/modules/ROOT/pages/appendix/gql-conformance/additional-cypher.adoc index 995b257eb..d39253a97 100644 --- a/modules/ROOT/pages/appendix/gql-conformance/additional-cypher.adoc +++ b/modules/ROOT/pages/appendix/gql-conformance/additional-cypher.adoc @@ -600,16 +600,16 @@ GQL supports `GRAPH TYPES` as a way of constraining a graph schema, but does not | Cypher feature | Description -| xref:constraints/managing-constraints.adoc#create-property-uniqueness-constraints[Property uniqueness constraints] +| xref:constraints/create-constraints.adoc#create-property-uniqueness-constraints[Property uniqueness constraints] | Ensures that the combined property values are unique for all nodes with a specific label or all relationships with a specific type. -| xref:constraints/managing-constraints.adoc#create-property-existence-constraints[Property existence constraints] +| xref:constraints/create-constraints.adoc#create-property-existence-constraints[Property existence constraints] | Ensures that a property exists either for all nodes with a specific label or for all relationships with a specific type. -| xref:constraints/managing-constraints.adoc#create-property-type-constraints[Property type constraints] +| xref:constraints/create-constraints.adoc#create-property-type-constraints[Property type constraints] | Ensures that a property has the required property type for all nodes with a specific label or for all relationships with a specific type. -| xref:constraints/managing-constraints.adoc#create-key-constraints[Key constraints] +| xref:constraints/create-constraints.adoc#create-key-constraints[Key constraints] | Ensures that all properties exist and that the combined property values are unique for all nodes with a specific label or all relationships with a specific type. |=== diff --git a/modules/ROOT/pages/appendix/tutorials/advanced-query-tuning.adoc b/modules/ROOT/pages/appendix/tutorials/advanced-query-tuning.adoc index 5d5816465..063b56d41 100644 --- a/modules/ROOT/pages/appendix/tutorials/advanced-query-tuning.adoc +++ b/modules/ROOT/pages/appendix/tutorials/advanced-query-tuning.adoc @@ -936,7 +936,7 @@ Predicates that will not work: [NOTE] ==== -If there is a xref:constraints/managing-constraints.adoc#create-property-existence-constraints[property existence constraint] on the property, no predicate is required to trigger the optimization. +If there is a xref:constraints/create-constraints.adoc#create-property-existence-constraints[property existence constraint] on the property, no predicate is required to trigger the optimization. For example, `CREATE CONSTRAINT constraint_name FOR (p:Person) REQUIRE p.name IS NOT NULL` Predicates with parameters, such as `WHERE n.prop > $param`, can trigger _index-backed ORDER BY_. diff --git a/modules/ROOT/pages/clauses/load-csv.adoc b/modules/ROOT/pages/clauses/load-csv.adoc index 02676a6b3..0b97405f0 100644 --- a/modules/ROOT/pages/clauses/load-csv.adoc +++ b/modules/ROOT/pages/clauses/load-csv.adoc @@ -662,7 +662,7 @@ For more `STRING` manipulation functions, see xref:functions/string.adoc[String === Create property uniqueness constraints -Always create xref:constraints/managing-constraints.adoc#create-property-uniqueness-constraints[property uniqueness constraints] prior to importing data, to avoid duplicates or colliding entities. +Always create xref:constraints/create-constraints.adoc#create-property-uniqueness-constraints[property uniqueness constraints] prior to importing data, to avoid duplicates or colliding entities. If the source file contains duplicated data and the right constraints are in place, Cypher raises an error. .Create a node property uniqueness constraints on person ID diff --git a/modules/ROOT/pages/clauses/merge.adoc b/modules/ROOT/pages/clauses/merge.adoc index 41fabe9c8..ae5daca98 100644 --- a/modules/ROOT/pages/clauses/merge.adoc +++ b/modules/ROOT/pages/clauses/merge.adoc @@ -25,7 +25,7 @@ If partial matches are needed, this can be accomplished by splitting a pattern i [NOTE] ==== Under concurrent updates, `MERGE` only guarantees the existence of the `MERGE` pattern, but not uniqueness. -To guarantee uniqueness of nodes with certain properties, a xref:constraints/managing-constraints.adoc#create-property-uniqueness-constraints[property uniqueness constraint] should be used. +To guarantee uniqueness of nodes with certain properties, a xref:constraints/create-constraints.adoc#create-property-uniqueness-constraints[property uniqueness constraint] should be used. See xref::clauses/merge.adoc#query-merge-using-unique-constraints[Using property uniqueness constraints with `MERGE`]. ==== @@ -511,7 +511,7 @@ This is in contrast to the example shown above in xref::clauses/merge.adoc#merge [[query-merge-using-unique-constraints]] == Using node property uniqueness constraints with `MERGE` -Cypher prevents getting conflicting results from `MERGE` when using patterns that involve xref:constraints/managing-constraints.adoc#create-property-uniqueness-constraints[property uniqueness constraints]. +Cypher prevents getting conflicting results from `MERGE` when using patterns that involve xref:constraints/create-constraints.adoc#create-property-uniqueness-constraints[property uniqueness constraints]. In this case, there must be at most one node that matches that pattern. For example, given two property node uniqueness constraints on `:Person(id)` and `:Person(ssn)`, a query such as `MERGE (n:Person {id: 12, ssn: 437})` will fail, if there are two different nodes (one with `id` 12 and one with `ssn` 437), or if there is only one node with only one of the properties. diff --git a/modules/ROOT/pages/clauses/optional-match.adoc b/modules/ROOT/pages/clauses/optional-match.adoc index 760ab6d7a..18fe5f50e 100644 --- a/modules/ROOT/pages/clauses/optional-match.adoc +++ b/modules/ROOT/pages/clauses/optional-match.adoc @@ -49,7 +49,7 @@ For example, the matching variables from one `MATCH` clause will provide the con However, there are two important differences between Neo4j and SQL which helps to explain `OPTIONAL MATCH` further. . While it is both possible and advised to enforce partial schemas using indexes and constraints, Neo4j offers a greater degree of schema flexibility than a relational database. -Nodes and relationships in a Neo4j database do not have to have a specific property set to them because other nodes or relationships in the same graph have that property (unless there is a xref:constraints/managing-constraints.adoc#create-property-existence-constraints[property existence constraint] created on the specific property). +Nodes and relationships in a Neo4j database do not have to have a specific property set to them because other nodes or relationships in the same graph have that property (unless there is a xref:constraints/create-constraints.adoc#create-property-existence-constraints[property existence constraint] created on the specific property). . Queries in Cypher are run as pipelines. If a clause returns no results, it will effectively end the query as subsequent clauses will have no data to execute upon. diff --git a/modules/ROOT/pages/constraints/managing-constraints.adoc b/modules/ROOT/pages/constraints/create-constraints.adoc similarity index 55% rename from modules/ROOT/pages/constraints/managing-constraints.adoc rename to modules/ROOT/pages/constraints/create-constraints.adoc index 79f7bbf16..7fa9a3424 100644 --- a/modules/ROOT/pages/constraints/managing-constraints.adoc +++ b/modules/ROOT/pages/constraints/create-constraints.adoc @@ -1,26 +1,11 @@ -:description: Information about creating, listing, and dropping Neo4j's constraints. -:page-aliases: constraints/examples.adoc -include::https://raw.githubusercontent.com/neo4j-graphacademy/courses/main/asciidoc/courses/cypher-indexes-constraints/ad.adoc[] -= Create, show, and drop constraints - -This page describes how to create, list, and drop constraints. -The following constraint types are available in Neo4j: - -* xref:constraints/managing-constraints.adoc#create-property-uniqueness-constraints[Property uniqueness constraints] -* xref:constraints/managing-constraints.adoc#create-property-existence-constraints[Property existence constraints] label:enterprise-edition[] -* xref:constraints/managing-constraints.adoc#create-property-type-constraints[Property type constraints] label:new[Introduced in 5.9] label:enterprise-edition[] -* xref:constraints/managing-constraints.adoc#create-key-constraints[Key constraints] label:enterprise-edition[] - - -[[create-constraint]] -== CREATE CONSTRAINT +:description: Information about creating Neo4j's constraints. += Create constraints Constraints are created with the `CREATE CONSTRAINT` command. When creating a constraint, it is recommended to provide a constraint name. This name must be unique among both indexes and constraints. If a name is not explicitly given, a unique name will be auto-generated. - [NOTE] Creating a constraint requires the link:{neo4j-docs-base-uri}/operations-manual/current/authentication-authorization/database-administration/#access-control-database-administration-constraints[`CREATE CONSTRAINT` privilege]. @@ -28,7 +13,7 @@ Creating a constraint requires the link:{neo4j-docs-base-uri}/operations-manual/ Adding constraints is an atomic operation that can take a while -- all existing data has to be scanned before a Neo4j DBMS can use a constraint. [[create-property-uniqueness-constraints]] -=== Create property uniqueness constraints +== Create property uniqueness constraints Property uniqueness constraints ensure that the property values are unique for all nodes with a specific label or all relationships with a specific type. For composite property uniqueness constraints on multiple properties, it is the combination of property values that must be unique. @@ -38,12 +23,8 @@ Property uniqueness constraints do not require all nodes or relationships to hav Only nodes or relationships that contain all properties specified in the constraint are subject to the uniqueness rule. Nodes or relationships missing one or more of the specified properties are not subject to this rule. -* xref:constraints/managing-constraints.adoc#create-single-property-uniqueness-constraint[] -* xref:constraints/managing-constraints.adoc#create-composite-property-uniqueness-constraint[] -* xref:constraints/managing-constraints.adoc#create-property-uniqueness-constraint-compliant-data[] - [[create-single-property-uniqueness-constraint]] -==== Create a single property uniqueness constraint +=== Create a single property uniqueness constraint Single property uniqueness constraints are created with the following commands: @@ -57,11 +38,13 @@ For the full command syntax to create a property uniqueness constraint, see xref ====== .Create a constraint requiring `Book` nodes to have unique `isbn` properties +// tag::schema_constraints_property_uniqueness[] [source, cypher] ---- CREATE CONSTRAINT book_isbn FOR (book:Book) REQUIRE book.isbn IS UNIQUE ---- +// end::schema_constraints_property_uniqueness[] .Result [source, queryresult] @@ -69,9 +52,6 @@ FOR (book:Book) REQUIRE book.isbn IS UNIQUE Added 1 constraint. ---- -[NOTE] -The detailed statistics view currently says `Unique constraints added: 1`. -It will be updated to say `Node property uniqueness constraints added: 1` in a future version of Neo4j. ====== @@ -92,14 +72,10 @@ FOR ()-[sequel:SEQUEL_OF]-() REQUIRE sequel.order IS UNIQUE Added 1 constraint. ---- -[NOTE] -The detailed statistics view currently says `Relationship uniqueness constraints added: 1`. -It will be updated to say `Relationship property uniqueness constraints added: 1` in a future version of Neo4j. - ====== [[create-composite-property-uniqueness-constraint]] -==== Create a composite property uniqueness constraint +=== Create a composite property uniqueness constraint Constraints created for multiple properties are called composite constraints. Note that the constrained properties must be parenthesized when creating composite property uniqueness constraints. @@ -132,11 +108,13 @@ Added 1 constraint. ====== .Create a constraint requiring `PREQUEL_OF` relationships to have unique combinations of `order` and `author` properties +// tag::schema_constraints_composite_property_uniqueness[] [source, cypher] ---- CREATE CONSTRAINT prequels FOR ()-[prequel:PREQUEL_OF]-() REQUIRE (prequel.order, prequel.author) IS UNIQUE ---- +// end::schema_constraints_composite_property_uniqueness[] .Result [source, queryresult] @@ -147,7 +125,7 @@ Added 1 constraint. ====== [[create-property-uniqueness-constraint-compliant-data]] -==== Create data that complies with existing property uniqueness constraints +=== Create data that complies with existing property uniqueness constraints .Create a node that complies with existing property uniqueness constraints ====== @@ -186,18 +164,14 @@ Added 2 labels, created 2 nodes, set 4 properties, created 1 relationship. [role=label--enterprise-edition] [[create-property-existence-constraints]] -=== Create property existence constraints +== Create property existence constraints Property existence constraints ensure that a property exists either for all nodes with a specific label or for all relationships with a specific type. Queries that try to create new nodes of the specified label, or relationships of the specified type, without the constrained property will fail. The same is true for queries that try to remove the mandatory property. -* xref:constraints/managing-constraints.adoc#create-single-property-existence-constraint[] -* xref:constraints/managing-constraints.adoc#create-property-existence-constraint-compliant-data[] - - [[create-single-property-existence-constraint]] -==== Create a single property existence constraint +=== Create a single property existence constraint Property existence constraints on single properties are created with the following commands: @@ -213,11 +187,13 @@ It is not possible to create composite existence constraints on several properti ====== .Create a constraint requiring `Author` nodes to have a `name` property +// tag::schema_constraints_property_existence[] [source, cypher] ---- CREATE CONSTRAINT author_name FOR (author:Author) REQUIRE author.name IS NOT NULL ---- +// end::schema_constraints_property_existence[] .Result [source, queryresult] @@ -247,7 +223,7 @@ Added 1 constraint. ====== [[create-property-existence-constraint-compliant-data]] -==== Create data that complies with existing property existence constraints +=== Create data that complies with existing property existence constraints .Create a node that complies with existing node property existence constraints ====== @@ -285,9 +261,9 @@ Added 2 labels, created 2 nodes, set 7 properties, created 1 relationship ====== -[role=label--enterprise-edition label--new-5.9] +[role=label--enterprise-edition] [[create-property-type-constraints]] -=== Create property type constraints +== Create property type constraints Property type constraints ensure that a property has the required data type for all nodes with a specific label or for all relationships with a specific type. Queries that attempt to add this property with the wrong data type or modify this property in a way that changes its data type for nodes of the specified label or relationships of the specified type will fail. @@ -295,14 +271,8 @@ Queries that attempt to add this property with the wrong data type or modify thi Property type constraints do not require all nodes or relationships to have the property. Nodes or relationships without the constrained property are not subject to this rule. -* xref:constraints/managing-constraints.adoc#create-single-property-type-constraint[] -* xref:constraints/managing-constraints.adoc#create-property-type-constraint-union-type[] -* xref:constraints/managing-constraints.adoc#type-constraints-allowed-properties[] -* xref:constraints/managing-constraints.adoc#fail-to-create-property-type-constraint-invalid-type[] -* xref:constraints/managing-constraints.adoc#create-property-type-constraint-compliant-data[] - [[create-single-property-type-constraint]] -==== Create a single property type constraint +=== Create a single property type constraint Property type constraints are created with the following commands: @@ -310,7 +280,7 @@ Property type constraints are created with the following commands: * Relationship property type constraints: `CREATE CONSTRAINT constraint_name FOR ()-[r:REL_TYPE]-() REQUIRE r.property IS :: `. `` refers to a specific Cypher data type, such as `STRING` or `INTEGER`. -For the types that properties can be constrained by, see xref:constraints/managing-constraints.adoc#type-constraints-allowed-properties[], and for information about different data types in Cypher, see xref:values-and-types/index.adoc[]. +For the types that properties can be constrained by, see xref:constraints/create-constraints.adoc#type-constraints-allowed-properties[], and for information about different data types in Cypher, see xref:values-and-types/index.adoc[]. For the full command syntax to create a property type constraint, see xref:constraints/syntax.adoc#create-property-type-constraints[Syntax -> Create property type constraints]. [NOTE] @@ -337,11 +307,13 @@ Added 1 constraint. ====== .Create a constraint requiring `order` properties on `PART_OF` relationships to be of type `INTEGER` +// tag::schema_constraints_property_type[] [source, cypher] ---- CREATE CONSTRAINT part_of FOR ()-[part:PART_OF]-() REQUIRE part.order IS :: INTEGER ---- +// end::schema_constraints_property_type[] .Result [source, queryresult] @@ -351,9 +323,8 @@ Added 1 constraint. ====== -[role=label--new-5.11] [[create-property-type-constraint-union-type]] -==== Create property type constraints with a union type +=== Create property type constraints with a union type A closed dynamic union allows a node or relationship property to maintain some type flexibility whilst preventing unexpected values from being stored. @@ -361,11 +332,13 @@ A closed dynamic union allows a node or relationship property to maintain some t ====== .Create a constraint requiring `tagline` properties on `Movie` nodes to be either of type `STRING` or `LIST` +// tag::schema_constraints_property_type_dynamic_union[] [source, cypher] ---- CREATE CONSTRAINT movie_tagline FOR (movie:Movie) REQUIRE movie.tagline IS :: STRING | LIST ---- +// end::schema_constraints_property_type_dynamic_union[] .Result [source, queryresult] @@ -394,7 +367,7 @@ Added 1 constraint. ====== [[type-constraints-allowed-properties]] -==== Allowed types +=== Allowed types The allowed property types for property type constraints are: @@ -425,7 +398,7 @@ The allowed property types for property type constraints are: For a complete reference describing all types available in Cypher, see the section on xref::values-and-types/property-structural-constructed.adoc#types-synonyms[types and their synonyms]. [[fail-to-create-property-type-constraint-invalid-type]] -==== Creating property type constraints on invalid types will fail +=== Creating property type constraints on invalid types will fail .Create a node property type constraint with an invalid type ====== @@ -445,7 +418,7 @@ Failed to create node property type constraint: Invalid property type `MAP`. ====== [[create-property-type-constraint-compliant-data]] -==== Create data that complies with existing property type constraints +=== Create data that complies with existing property type constraints .Create a node that complies with existing node property type constraint ====== @@ -486,7 +459,7 @@ Added 1 label, added 1 node, created 1 relationship, set 2 properties [role=label--enterprise-edition] [[create-key-constraints]] -=== Create key constraints +== Create key constraints Key constraints ensure that the property exist and the property value is unique for all nodes with a specific label or all relationships with a specific type. For composite key constraints on multiple properties, all properties must exists and the combination of property values must be unique. @@ -494,12 +467,8 @@ For composite key constraints on multiple properties, all properties must exists Queries that try to create new nodes of the specified label, or relationships of the specified type, without the constrained property will fail. The same is true for queries that try to remove the mandatory property or add duplicated property values. -* xref:constraints/managing-constraints.adoc#create-single-property-key-constraint[] -* xref:constraints/managing-constraints.adoc#create-composite-key-constraint[] -* xref:constraints/managing-constraints.adoc#create-key-constraint-compliant-data[] - [[create-single-property-key-constraint]] -==== Create a single property key constraint +=== Create a single property key constraint Single property key constraints are created with the following commands: @@ -512,11 +481,13 @@ For the full command syntax to create a key constraint, see xref:constraints/syn ====== .Create a constraint requiring `Director` nodes to have a unique `imdbId` property as a node key. +// tag::schema_constraints_key[] [source, cypher] ---- CREATE CONSTRAINT director_imdbId FOR (director:Director) REQUIRE (director.imdbId) IS NODE KEY ---- +// end::schema_constraints_key[] .Result [source, queryresult] @@ -546,7 +517,7 @@ Added 1 constraint. ====== [[create-composite-key-constraint]] -==== Create a composite key constraint +=== Create a composite key constraint Constraints created for multiple properties are called composite constraints. Note that the constrained properties must be parenthesized when creating composite key constraints. @@ -580,11 +551,13 @@ Added 1 constraint. ====== .Create a constraint requiring `KNOWS` relationships to have a unique combination of `since` and `how` properties as a relationship key +// tag::schema_constraints_composite_key[] [source, cypher] ---- CREATE CONSTRAINT knows_since_how FOR ()-[knows:KNOWS]-() REQUIRE (knows.since, knows.how) IS RELATIONSHIP KEY ---- +// end::schema_constraints_composite_key[] .Result [source, queryresult] @@ -595,7 +568,7 @@ Added 1 constraint. ====== [[create-key-constraint-compliant-data]] -==== Create data that complies with existing key constraints +=== Create data that complies with existing key constraints .Create a node that complies with existing node key constraints ====== @@ -632,10 +605,9 @@ Added 2 labels, created 2 nodes, set 7 properties, created 1 relationship. ====== - [role=label--new-5.16] [[create-constraint-with-parameter]] -=== Create a constraint with a parameter +== Create a constraint with a parameter All constraint types can be created with a parameterized name. @@ -651,11 +623,13 @@ All constraint types can be created with a parameterized name. ---- .Create a node property uniqueness constraint with a parameterized name +// tag::schema_constraints_parameter[] [source, cypher] ---- CREATE CONSTRAINT $name FOR (book:Book) REQUIRE book.prop1 IS UNIQUE ---- +// end::schema_constraints_parameter[] .Result [source, queryresult] @@ -692,7 +666,7 @@ Added 1 constraint. ====== [[handling-multiple-constraints]] -=== Handling multiple constraints +== Handling multiple constraints Creating an already existing constraint will fail. This includes the following scenarios: @@ -712,16 +686,13 @@ However, some constraint types are allowed on the same label/relationship type a For example, it is possible to have a property uniqueness and a property existence constraint on the same label/relationship type and property combination, though this would be the equivalent of having a node or relationship key constraint. A more useful example would be to combine a property type and a property existence constraint to ensure that the property exists and has the given type. -* xref:constraints/managing-constraints.adoc#create-a-constraint-if-not-exist[] -* xref:constraints/managing-constraints.adoc#create-an-already-existing-constraint[] - [[create-a-constraint-if-not-exist]] -==== Handling existing constraints when creating a constraint +=== Handling existing constraints when creating a constraint To avoid failing on existing constraints, `IF NOT EXISTS` can be added to the `CREATE` command. 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. For property type constraints the property type also needs to be the same. -As of Neo4j 5.17, an informational notification is instead returned showing the existing constraint which blocks the creation. +Instead, an informational notification is returned showing the existing constraint which blocks the creation. .Create a constraint identical to an existing constraint ====== @@ -805,7 +776,7 @@ Because a node property existence constraint named `author_name` already exists, ====== [[create-an-already-existing-constraint]] -==== Creating an already existing constraint will fail +=== Creating an already existing constraint will fail Creating a constraint with the same name or on the same node label or relationship type and properties that are already constrained by a constraint of the same type will fail. Property uniqueness and key constraints are also not allowed on the same schema. @@ -823,12 +794,9 @@ FOR ()-[sequel:SEQUEL_OF]-() REQUIRE sequel.order IS UNIQUE .Error message [source, error] ---- -An equivalent constraint already exists, 'Constraint( id=5, name='sequels', type='RELATIONSHIP UNIQUENESS', schema=()-[:SEQUEL_OF {order}]-(), ownedIndex=4 )'. +An equivalent constraint already exists, 'Constraint( id=5, name='sequels', type='RELATIONSHIP PROPERTY UNIQUENESS', schema=()-[:SEQUEL_OF {order}]-(), ownedIndex=4 )'. ---- -[NOTE] -The constraint type will be updated to say `RELATIONSHIP PROPERTY UNIQUENESS` in a future version of Neo4j. - ====== .Create a constraint with a different name but on the same schema as an existing constraint @@ -844,12 +812,9 @@ FOR (book:Book) REQUIRE book.isbn IS UNIQUE .Error message [source, error] ---- -Constraint already exists: Constraint( id=3, name='book_isbn', type='UNIQUENESS', schema=(:Book {isbn}), ownedIndex=2 ) +Constraint already exists: Constraint( id=3, name='book_isbn', type='NODE PROPERTY UNIQUENESS', schema=(:Book {isbn}), ownedIndex=2 ) ---- -[NOTE] -The constraint type will be updated to say `NODE PROPERTY UNIQUENESS` in a future version of Neo4j. - ====== .Creating a constraint with the same name but on a different schema as an existing constraint @@ -901,19 +866,16 @@ CREATE CONSTRAINT book_titles FOR (book:Book) REQUIRE (book.title, book.publicat .Error message [source, error] ---- -Constraint already exists: Constraint( id=7, name='book_title_year', type='UNIQUENESS', schema=(:Book {title, publicationYear}), ownedIndex=6 ) +Constraint already exists: Constraint( id=7, name='book_title_year', type='NODE PROPERTY UNIQUENESS', schema=(:Book {title, publicationYear}), ownedIndex=6 ) ---- ====== [[constraints-and-indexes]] -=== Constraints and indexes - -* xref:constraints/managing-constraints.adoc#constraints-and-backing-indexes[] -* xref:constraints/managing-constraints.adoc#constraint-failures-and-indexes[] +== Constraints and indexes [[constraints-and-backing-indexes]] -==== Constraints and backing indexes +=== Constraints and backing indexes Property uniqueness constraints and key constraints are backed by xref:indexes/search-performance-indexes/managing-indexes.adoc#create-range-index[range indexes]. This means that creating a property uniqueness or key constraint will create a range index with the same name, node label/relationship type and property combination as its owning constraint. @@ -930,7 +892,7 @@ The index makes these checks much faster by enabling direct lookups instead of s Cypher will use the indexes with an owning constraint in the same way that it utilizes other search-performance indexes. For more information about how indexes impact query performance, see xref:indexes/search-performance-indexes/using-indexes.adoc[]. -These indexes are listed in the `owningConstraint` column returned by the xref:indexes/search-performance-indexes/managing-indexes.adoc#list-indexes[`SHOW INDEX`] command, and the `ownedIndex` column returned by the xref:constraints/managing-constraints.adoc#list-constraints[`SHOW CONSTRAINT`] command. +These indexes are listed in the `owningConstraint` column returned by the xref:indexes/search-performance-indexes/managing-indexes.adoc#list-indexes[`SHOW INDEX`] command, and the `ownedIndex` column returned by the xref:constraints/list-constraints.adoc[`SHOW CONSTRAINT`] command. .List constraints with backing indexes ====== @@ -947,15 +909,15 @@ SHOW CONSTRAINTS WHERE ownedIndex IS NOT NULL +--------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | id | name | type | entityType | labelsOrTypes | properties | ownedIndex | propertyType | +--------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| 21 | "actor_fullname" | "NODE_KEY" | "NODE" | ["Actor"] | ["firstname", "surname"] | "actor_fullname" | NULL | -| 3 | "book_isbn" | "UNIQUENESS" | "NODE" | ["Book"] | ["isbn"] | "book_isbn" | NULL | -| 7 | "book_title_year" | "UNIQUENESS" | "NODE" | ["Book"] | ["title", "publicationYear"] | "book_title_year" | NULL | -| 17 | "director_imdbId" | "NODE_KEY" | "NODE" | ["Director"] | ["imdbId"] | "director_imdbId" | NULL | -| 23 | "knows_since_how" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["KNOWS"] | ["since", "how"] | "knows_since_how" | NULL | -| 25 | "node_uniqueness_param" | "UNIQUENESS" | "NODE" | ["Book"] | ["prop1"] | "node_uniqueness_param" | NULL | -| 19 | "ownershipId" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["OWNS"] | ["ownershipId"] | "ownershipId" | NULL | -| 9 | "prequels" | "RELATIONSHIP_UNIQUENESS" | "RELATIONSHIP" | ["PREQUEL_OF"] | ["order", "author"] | "prequels" | NULL | -| 5 | "sequels" | "RELATIONSHIP_UNIQUENESS" | "RELATIONSHIP" | ["SEQUEL_OF"] | ["order"] | "sequels" | NULL | +| 10 | "actor_fullname" | "NODE_KEY" | "NODE" | ["Actor"] | ["firstname", "surname"] | "actor_fullname" | NULL | +| 63 | "book_isbn" | "UNIQUENESS" | "NODE" | ["Book"] | ["isbn"] | "book_isbn" | NULL | +| 3 | "book_title_year" | "UNIQUENESS" | "NODE" | ["Book"] | ["title", "publicationYear"] | "book_title_year" | NULL | +| 13 | "director_imdbId" | "NODE_KEY" | "NODE" | ["Director"] | ["imdbId"] | "director_imdbId" | NULL | +| 41 | "knows_since_how" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["KNOWS"] | ["since", "how"] | "knows_since_how" | NULL | +| 28 | "node_uniqueness_param" | "UNIQUENESS" | "NODE" | ["Book"] | ["prop1"] | "node_uniqueness_param" | NULL | +| 38 | "ownershipId" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["OWNS"] | ["ownershipId"] | "ownershipId" | NULL | +| 4 | "prequels" | "RELATIONSHIP_UNIQUENESS" | "RELATIONSHIP" | ["PREQUEL_OF"] | ["order", "author"] | "prequels" | NULL | +| 65 | "sequels" | "RELATIONSHIP_UNIQUENESS" | "RELATIONSHIP" | ["SEQUEL_OF"] | ["order"] | "sequels" | NULL | +--------------------------------------------------------------------------------------------------------------------------------------------------------------------+ ---- @@ -994,7 +956,7 @@ SHOW INDEXES WHERE owningConstraint IS NOT NULL Property existence and property type constraints are not backed by indexes. [[constraint-failures-and-indexes]] -==== Constraint failures and indexes +=== Constraint failures and indexes Attempting to create any type of constraint with the same name as an existing index will fail. @@ -1049,15 +1011,10 @@ A constraint cannot be created until the index has been dropped. [[constraints-and-data-violation-scenarios]] -=== Constraints and data violation scenarios - -* xref:constraints/managing-constraints.adoc#create-data-that-violates-a-constraint[] -* xref:constraints/managing-constraints.adoc#removing-an-existing-constrained-property-will-fail[] -* xref:constraints/managing-constraints.adoc#modifying-property-constrained-property-will-fail[] -* xref:constraints/managing-constraints.adoc#fail-to-create-constraint-due-to-existing-data[] +== Constraints and data violation scenarios [[create-data-that-violates-a-constraint]] -==== Creating data that violates existing constraints will fail +=== Creating data that violates existing constraints will fail .Existing constraints preventing data creation [cols="4", options="header"] @@ -1162,7 +1119,7 @@ Node(0) with label `Actor` must have the properties (`firstname`, `surname`) ====== [[removing-an-existing-constrained-property-will-fail]] -==== Removing existence and key constrained properties will fail +=== Removing existence and key constrained properties will fail .Remove a node property existence constrained property ====== @@ -1202,7 +1159,7 @@ Node(0) with label `Actor` must have the properties (`firstname`, `surname`) ====== [[modifying-property-constrained-property-will-fail]] -==== Modifying type constrained properties will fail +=== Modifying type constrained properties will fail .Modify a type constrained property ====== @@ -1224,7 +1181,7 @@ Node(9) with label `Movie` required the property `title` to be of type `STRING`, [[fail-to-create-constraint-due-to-existing-data]] -==== Creating constraints when there exists conflicting data will fail +=== Creating constraints when there exists conflicting data will fail .Existing data preventing constraint creation [cols="4", options="header"] @@ -1279,7 +1236,7 @@ Either use xref:indexes/search-performance-indexes/managing-indexes.adoc[indexes .Error message [source, error] ---- -Unable to create Constraint( name='book_title', type='UNIQUENESS', schema=(:Book {title}) ): +Unable to create Constraint( name='book_title', type='NODE PROPERTY UNIQUENESS', schema=(:Book {title}) ): Both Node(0) and Node(1) have the label `Book` and property `title` = 'Moby Dick' ---- @@ -1420,348 +1377,4 @@ WHERE r.prop IS NULL RETURN r AS relationship, 'non-existing' AS reason ---- -|=== - -[[list-constraints]] -== SHOW CONSTRAINTS - -To list all constraints with the default output columns, use `SHOW CONSTRAINTS`. -If all columns are required, use `SHOW CONSTRAINTS YIELD *`. -For the full command syntax to list constraints, see xref:constraints/syntax.adoc#list-constraints[Syntax -> SHOW CONSTRAINTS]. - -One of the output columns from `SHOW CONSTRAINTS` is the name of the constraint. -This can be used to drop the constraint with the xref::constraints/managing-constraints.adoc#drop-constraint[`DROP CONSTRAINT` command]. - -[NOTE] -Listing constraints requires the link:{neo4j-docs-base-uri}/operations-manual/current/authentication-authorization/database-administration/#access-control-database-administration-constraints[`SHOW CONSTRAINTS` privilege]. - -.List all constraints with default output columns -====== - -.Query -[source, cypher, test-exclude-cols=id] ----- -SHOW CONSTRAINTS ----- - -.Result -[source, queryresult] ----- -+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| id | name | type | entityType | labelsOrTypes | properties | ownedIndex | propertyType | -+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| 21 | "actor_fullname" | "NODE_KEY" | "NODE" | ["Actor"] | ["firstname", "surname"] | "actor_fullname" | NULL | -| 10 | "author_name" | "NODE_PROPERTY_EXISTENCE" | "NODE" | ["Author"] | ["name"] | NULL | NULL | -| 3 | "book_isbn" | "UNIQUENESS" | "NODE" | ["Book"] | ["isbn"] | "book_isbn" | NULL | -| 7 | "book_title_year" | "UNIQUENESS" | "NODE" | ["Book"] | ["title", "publicationYear"] | "book_title_year" | NULL | -| 17 | "director_imdbId" | "NODE_KEY" | "NODE" | ["Director"] | ["imdbId"] | "director_imdbId" | NULL | -| 23 | "knows_since_how" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["KNOWS"] | ["since", "how"] | "knows_since_how" | NULL | -| 14 | "movie_tagline" | "NODE_PROPERTY_TYPE" | "NODE" | ["Movie"] | ["tagline"] | NULL | "STRING | LIST" | -| 12 | "movie_title" | "NODE_PROPERTY_TYPE" | "NODE" | ["Movie"] | ["title"] | NULL | "STRING" | -| 25 | "node_uniqueness_param" | "UNIQUENESS" | "NODE" | ["Book"] | ["prop1"] | "node_uniqueness_param" | NULL | -| 19 | "ownershipId" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["OWNS"] | ["ownershipId"] | "ownershipId" | NULL | -| 13 | "part_of" | "RELATIONSHIP_PROPERTY_TYPE" | "RELATIONSHIP" | ["PART_OF"] | ["order"] | NULL | "INTEGER" | -| 15 | "part_of_tags" | "RELATIONSHIP_PROPERTY_TYPE" | "RELATIONSHIP" | ["PART_OF"] | ["tags"] | NULL | "STRING | LIST" | -| 9 | "prequels" | "RELATIONSHIP_UNIQUENESS" | "RELATIONSHIP" | ["PREQUEL_OF"] | ["order", "author"] | "prequels" | NULL | -| 26 | "rel_exist_param" | "RELATIONSHIP_PROPERTY_EXISTENCE" | "RELATIONSHIP" | ["WROTE"] | ["published"] | NULL | NULL | -| 5 | "sequels" | "RELATIONSHIP_UNIQUENESS" | "RELATIONSHIP" | ["SEQUEL_OF"] | ["order"] | "sequels" | NULL | -| 11 | "wrote_year" | "RELATIONSHIP_PROPERTY_EXISTENCE" | "RELATIONSHIP" | ["WROTE"] | ["year"] | NULL | NULL | -+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ ----- - -====== - -.List all constraints with full details -====== - -To return the full details of the constraints on a database, use `SHOW CONSTRAINTS YIELD *` - -.List all constraints with `YIELD *` -[source, cypher, test-exclude-cols=id] ----- -SHOW CONSTRAINTS YIELD * ----- - -.Result -[source, queryresult] ----- -+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| id | name | type | entityType | labelsOrTypes | properties | ownedIndex | propertyType | options | createStatement | -+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| 21 | "actor_fullname" | "NODE_KEY" | "NODE" | ["Actor"] | ["firstname", "surname"] | "actor_fullname" | NULL | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `actor_fullname` FOR (n:`Actor`) REQUIRE (n.`firstname`, n.`surname`) IS NODE KEY" | -| 10 | "author_name" | "NODE_PROPERTY_EXISTENCE" | "NODE" | ["Author"] | ["name"] | NULL | NULL | NULL | "CREATE CONSTRAINT `author_name` FOR (n:`Author`) REQUIRE (n.`name`) IS NOT NULL" | -| 3 | "book_isbn" | "UNIQUENESS" | "NODE" | ["Book"] | ["isbn"] | "book_isbn" | NULL | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `book_isbn` FOR (n:`Book`) REQUIRE (n.`isbn`) IS UNIQUE" | -| 7 | "book_title_year" | "UNIQUENESS" | "NODE" | ["Book"] | ["title", "publicationYear"] | "book_title_year" | NULL | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `book_title_year` FOR (n:`Book`) REQUIRE (n.`title`, n.`publicationYear`) IS UNIQUE" | -| 17 | "director_imdbId" | "NODE_KEY" | "NODE" | ["Director"] | ["imdbId"] | "director_imdbId" | NULL | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `director_imdbId` FOR (n:`Director`) REQUIRE (n.`imdbId`) IS NODE KEY" | -| 23 | "knows_since_how" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["KNOWS"] | ["since", "how"] | "knows_since_how" | NULL | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `knows_since_how` FOR ()-[r:`KNOWS`]-() REQUIRE (r.`since`, r.`how`) IS RELATIONSHIP KEY" | -| 14 | "movie_tagline" | "NODE_PROPERTY_TYPE" | "NODE" | ["Movie"] | ["tagline"] | NULL | "STRING | LIST" | NULL | "CREATE CONSTRAINT `movie_tagline` FOR (n:`Movie`) REQUIRE (n.`tagline`) IS :: STRING | LIST" | -| 12 | "movie_title" | "NODE_PROPERTY_TYPE" | "NODE" | ["Movie"] | ["title"] | NULL | "STRING" | NULL | "CREATE CONSTRAINT `movie_title` FOR (n:`Movie`) REQUIRE (n.`title`) IS :: STRING" | -| 25 | "node_uniqueness_param" | "UNIQUENESS" | "NODE" | ["Book"] | ["prop1"] | "node_uniqueness_param" | NULL | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `node_uniqueness_param` FOR (n:`Book`) REQUIRE (n.`prop1`) IS UNIQUE" | -| 19 | "ownershipId" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["OWNS"] | ["ownershipId"] | "ownershipId" | NULL | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `ownershipId` FOR ()-[r:`OWNS`]-() REQUIRE (r.`ownershipId`) IS RELATIONSHIP KEY" | -| 13 | "part_of" | "RELATIONSHIP_PROPERTY_TYPE" | "RELATIONSHIP" | ["PART_OF"] | ["order"] | NULL | "INTEGER" | NULL | "CREATE CONSTRAINT `part_of` FOR ()-[r:`PART_OF`]-() REQUIRE (r.`order`) IS :: INTEGER" | -| 15 | "part_of_tags" | "RELATIONSHIP_PROPERTY_TYPE" | "RELATIONSHIP" | ["PART_OF"] | ["tags"] | NULL | "STRING | LIST" | NULL | "CREATE CONSTRAINT `part_of_tags` FOR ()-[r:`PART_OF`]-() REQUIRE (r.`tags`) IS :: STRING | LIST" | -| 9 | "prequels" | "RELATIONSHIP_UNIQUENESS" | "RELATIONSHIP" | ["PREQUEL_OF"] | ["order", "author"] | "prequels" | NULL | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `prequels` FOR ()-[r:`PREQUEL_OF`]-() REQUIRE (r.`order`, r.`author`) IS UNIQUE" | -| 26 | "rel_exist_param" | "RELATIONSHIP_PROPERTY_EXISTENCE" | "RELATIONSHIP" | ["WROTE"] | ["published"] | NULL | NULL | NULL | "CREATE CONSTRAINT `rel_exist_param` FOR ()-[r:`WROTE`]-() REQUIRE (r.`published`) IS NOT NULL" | -| 5 | "sequels" | "RELATIONSHIP_UNIQUENESS" | "RELATIONSHIP" | ["SEQUEL_OF"] | ["order"] | "sequels" | NULL | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `sequels` FOR ()-[r:`SEQUEL_OF`]-() REQUIRE (r.`order`) IS UNIQUE" | -| 11 | "wrote_year" | "RELATIONSHIP_PROPERTY_EXISTENCE" | "RELATIONSHIP" | ["WROTE"] | ["year"] | NULL | NULL | NULL | "CREATE CONSTRAINT `wrote_year` FOR ()-[r:`WROTE`]-() REQUIRE (r.`year`) IS NOT NULL" | -+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ ----- -====== - -[NOTE] -The `type` column returns `UNIQUENESS` for the node property uniqueness constraint and `RELATIONSHIP_UNIQUENESS` for the relationship property uniqueness constraint. -This will be updated in a future version of Neo4j. -Node property uniqueness constraints will be updated to `NODE_PROPERTY_UNIQUENESS` and relationship property uniqueness constraints to `RELATIONSHIP_PROPERTY_UNIQUENESS`. - -[[list-constraints-with-filtering]] -=== Listing constraints with filtering - -The `SHOW CONSTRAINTS` command can be filtered in various ways. -The filtering of rows can be done using constraint type keywords or a `WHERE` clause, while filtering of columns is achieved by specifying the desired columns in a `YIELD` clause. - -.List only specific constraint types -====== - -.List only key constraints -[source, cypher, test-exclude-cols=id] ----- -SHOW KEY CONSTRAINTS ----- - -.Result -[source, queryresult] ----- -+--------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| id | name | type | entityType | labelsOrTypes | properties | ownedIndex | propertyType | -+--------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| 21 | "actor_fullname" | "NODE_KEY" | "NODE" | ["Actor"] | ["firstname", "surname"] | "actor_fullname" | NULL | -| 17 | "director_imdbId" | "NODE_KEY" | "NODE" | ["Director"] | ["imdbId"] | "director_imdbId" | NULL | -| 23 | "knows_since_how" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["KNOWS"] | ["since", "how"] | "knows_since_how" | NULL | -| 19 | "ownershipId" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["OWNS"] | ["ownershipId"] | "ownershipId" | NULL | -+--------------------------------------------------------------------------------------------------------------------------------------------------------------+ ----- - -For a full list of all the constraint types (and synonyms) available in this command see xref:constraints/syntax.adoc#list-constraints[Syntax -> SHOW CONSTRAINTS]. - -====== - - -.Filtering constraints using the `WHERE` clause -====== - -.List only constraints with a `RELATIONSHIP` `entityType` -[source, cypher, test-exclude-cols=id] ----- -SHOW CONSTRAINTS -WHERE entityType = 'RELATIONSHIP' ----- - -.Result -[source, queryresult] ----- -+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| id | name | type | entityType | labelsOrTypes | properties | ownedIndex | propertyType | -+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| 23 | "knows_since_how" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["KNOWS"] | ["since", "how"] | "knows_since_how" | NULL | -| 19 | "ownershipId" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["OWNS"] | ["ownershipId"] | "ownershipId" | NULL | -| 13 | "part_of" | "RELATIONSHIP_PROPERTY_TYPE" | "RELATIONSHIP" | ["PART_OF"] | ["order"] | NULL | "INTEGER" | -| 15 | "part_of_tags" | "RELATIONSHIP_PROPERTY_TYPE" | "RELATIONSHIP" | ["PART_OF"] | ["tags"] | NULL | "STRING | LIST" | -| 9 | "prequels" | "RELATIONSHIP_UNIQUENESS" | "RELATIONSHIP" | ["PREQUEL_OF"] | ["order", "author"] | "prequels" | NULL | -| 26 | "rel_exist_param" | "RELATIONSHIP_PROPERTY_EXISTENCE" | "RELATIONSHIP" | ["WROTE"] | ["published"] | NULL | NULL | -| 5 | "sequels" | "RELATIONSHIP_UNIQUENESS" | "RELATIONSHIP" | ["SEQUEL_OF"] | ["order"] | "sequels" | NULL | -| 11 | "wrote_year" | "RELATIONSHIP_PROPERTY_EXISTENCE" | "RELATIONSHIP" | ["WROTE"] | ["year"] | NULL | NULL | -+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ ----- - -====== - - -.Returning specific columns for all constraints -====== - -It is possible to return only specific columns of the available constraints using the `YIELD` clause: - -.List only the `name`, `type`, and `createStatement` columns -[source, cypher, test-exclude-cols=id] ----- -SHOW CONSTRAINTS -YIELD name, type, createStatement ----- - -.Result -[source, queryresult] ----- -+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| name | type | createStatement | -+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| "actor_fullname" | "NODE_KEY" | "CREATE CONSTRAINT `actor_fullname` FOR (n:`Actor`) REQUIRE (n.`firstname`, n.`surname`) IS NODE KEY" | -| "author_name" | "NODE_PROPERTY_EXISTENCE" | "CREATE CONSTRAINT `author_name` FOR (n:`Author`) REQUIRE (n.`name`) IS NOT NULL" | -| "book_isbn" | "UNIQUENESS" | "CREATE CONSTRAINT `book_isbn` FOR (n:`Book`) REQUIRE (n.`isbn`) IS UNIQUE" | -| "book_title_year" | "UNIQUENESS" | "CREATE CONSTRAINT `book_title_year` FOR (n:`Book`) REQUIRE (n.`title`, n.`publicationYear`) IS UNIQUE" | -| "constraint_with_provider" | "NODE_KEY" | "CREATE CONSTRAINT `constraint_with_provider` FOR (n:`Actor`) REQUIRE (n.`surname`) IS NODE KEY" | -| "director_imdbId" | "NODE_KEY" | "CREATE CONSTRAINT `director_imdbId` FOR (n:`Director`) REQUIRE (n.`imdbId`) IS NODE KEY" | -| "knows_since_how" | "RELATIONSHIP_KEY" | "CREATE CONSTRAINT `knows_since_how` FOR ()-[r:`KNOWS`]-() REQUIRE (r.`since`, r.`how`) IS RELATIONSHIP KEY" | -| "movie_tagline" | "NODE_PROPERTY_TYPE" | "CREATE CONSTRAINT `movie_tagline` FOR (n:`Movie`) REQUIRE (n.`tagline`) IS :: STRING | LIST" | -| "movie_title" | "NODE_PROPERTY_TYPE" | "CREATE CONSTRAINT `movie_title` FOR (n:`Movie`) REQUIRE (n.`title`) IS :: STRING" | -| "node_uniqueness_param" | "UNIQUENESS" | "CREATE CONSTRAINT `node_uniqueness_param` FOR (n:`Book`) REQUIRE (n.`prop1`) IS UNIQUE" | -| "ownershipId" | "RELATIONSHIP_KEY" | "CREATE CONSTRAINT `ownershipId` FOR ()-[r:`OWNS`]-() REQUIRE (r.`ownershipId`) IS RELATIONSHIP KEY" | -| "part_of" | "RELATIONSHIP_PROPERTY_TYPE" | "CREATE CONSTRAINT `part_of` FOR ()-[r:`PART_OF`]-() REQUIRE (r.`order`) IS :: INTEGER" | -| "part_of_tags" | "RELATIONSHIP_PROPERTY_TYPE" | "CREATE CONSTRAINT `part_of_tags` FOR ()-[r:`PART_OF`]-() REQUIRE (r.`tags`) IS :: STRING | LIST" | -| "prequels" | "RELATIONSHIP_UNIQUENESS" | "CREATE CONSTRAINT `prequels` FOR ()-[r:`PREQUEL_OF`]-() REQUIRE (r.`order`, r.`author`) IS UNIQUE" | -| "rel_exist_param" | "RELATIONSHIP_PROPERTY_EXISTENCE" | "CREATE CONSTRAINT `rel_exist_param` FOR ()-[r:`WROTE`]-() REQUIRE (r.`published`) IS NOT NULL" | -| "sequels" | "RELATIONSHIP_UNIQUENESS" | "CREATE CONSTRAINT `sequels` FOR ()-[r:`SEQUEL_OF`]-() REQUIRE (r.`order`) IS UNIQUE" | -| "wrote_year" | "RELATIONSHIP_PROPERTY_EXISTENCE" | "CREATE CONSTRAINT `wrote_year` FOR ()-[r:`WROTE`]-() REQUIRE (r.`year`) IS NOT NULL" | -+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ ----- - -====== - - -[[list-constraints-result-columns]] -=== Result columns for listing constraints - -.Listing constraints output -[options="header", width="100%", cols="4m,6a,2m"] -|=== -| Column | Description | Type - -| id -| The id of the constraint. label:default-output[] -| INTEGER - -| name -| Name of the constraint (explicitly set by the user or automatically assigned). label:default-output[] -| STRING - -| type -| The ConstraintType of this constraint (`UNIQUENESS` (node uniqueness), `RELATIONSHIP_UNIQUENESS`, `NODE_PROPERTY_EXISTENCE`, `RELATIONSHIP_PROPERTY_EXISTENCE`, `NODE_PROPERTY_TYPE`, `RELATIONSHIP_PROPERTY_TYPE`, `NODE_KEY`, or `RELATIONSHIP_KEY`). label:default-output[] - -[NOTE] -`UNIQUENESS` and `RELATIONSHIP_UNIQUENESS` will be updated to say `NODE_PROPERTY_UNIQUENESS` and `RELATIONSHIP_PROPERTY_UNIQUENESS` respectively in a future version of Neo4j. -| STRING - -| entityType -| Type of entities this constraint represents (`NODE` or `RELATIONSHIP`). label:default-output[] -| STRING - -| labelsOrTypes -| The labels or relationship types of this constraint. -The list returned will only include a single value (the name of the constrained node label or relationship type). label:default-output[] -| LIST - -| properties -| The properties of this constraint. label:default-output[] -| LIST - -| ownedIndex -| The name of the index associated with the constraint or `null`, in case no index is associated with it. label:default-output[] -| STRING - -| propertyType -| The property type the property is restricted to for property type constraints, or `null` for the other constraints. -label:default-output[] label:new[Introduced in 5.9] -| STRING - -| options -| The options passed to `CREATE` command, for the index associated to the constraint, or `null` if no index is associated with the constraint. -| MAP - -| createStatement -| Statement used to create the constraint. -| STRING - -|=== - -[[drop-constraint]] -== DROP CONSTRAINT - -Constraints are dropped using the `DROP CONSTRAINT` command. -For the full command syntax to drop constraints, see xref:constraints/syntax.adoc#drop-constraint[Syntax -> DROP CONSTRAINT]. - -[NOTE] -Dropping a constraint requires the link:{neo4j-docs-base-uri}/operations-manual/current/authentication-authorization/database-administration/#access-control-database-administration-constraints[`DROP CONSTRAINT` privilege]. - -[[drop-constraint-by-name]] -=== Drop a constraint by name - -A constraint can be dropped using the name with the `DROP CONSTRAINT constraint_name` command. -It is the same command for all constraint types. -The name of the constraint can be found using the xref:constraints/managing-constraints.adoc#list-constraints[`SHOW CONSTRAINTS` command], given in the output column `name`. - -.Drop a constraint by name -====== - -.Drop the constraint `book_isbn` -[source, cypher] ----- -DROP CONSTRAINT book_isbn ----- - -.Result -[source, queryresult] ----- -Removed 1 constraint. ----- - -====== - -[role=label--new-5.16] -[[drop-constraint-with-parameter]] -=== Drop a constraint with a parameter - -Constraints can be dropped with a parameterized name. - -.Drop a constraint using a parameter -====== - -.Parameters -[source, parameters] ----- -{ - "name": "actor_fullname" -} ----- - -.Drop a constraint with a parameterized name -[source, cypher] ----- -DROP CONSTRAINT $name ----- - -.Result -[source, queryresult] ----- -Removed 1 constraint. ----- - -====== - -[[drop-constraint-nonexisting-constraint]] -=== Drop a non-existing constraint - -If it is uncertain if any constraint with a given name exists and you want to drop it if it does but not get an error should it not, use `IF EXISTS`. -This will ensure that no error is thrown. -As of Neo4j 5.17, an informational notification is returned stating that the constraint does not exist. - -.Drop a non-existing constraint -====== - -.Drop the non-existing constraint `missing_constraint_name` -[source, cypher] ----- -DROP CONSTRAINT missing_constraint_name IF EXISTS ----- - -.Result -[source, queryresult] ----- -(no changes, no records) ----- - -.Notification -[source] ----- -`DROP CONSTRAINT missing_constraint_name IF EXISTS` has no effect. `missing_constraint_name` does not exist. ----- - -====== \ No newline at end of file +|=== \ No newline at end of file diff --git a/modules/ROOT/pages/constraints/drop-constraints.adoc b/modules/ROOT/pages/constraints/drop-constraints.adoc new file mode 100644 index 000000000..27af43525 --- /dev/null +++ b/modules/ROOT/pages/constraints/drop-constraints.adoc @@ -0,0 +1,138 @@ +:description: Information about droppping Neo4j's constraints. += Drop constraints + +Constraints are dropped using the `DROP CONSTRAINT` command. +For the full command syntax to drop constraints, see xref:constraints/syntax.adoc#drop-constraint[Syntax -> Drop constraints]. +The constraints dropped on this page are created on the page xref:constraints/create-constraints.adoc[]. + +[NOTE] +Dropping a constraint requires the link:{neo4j-docs-base-uri}/operations-manual/current/authentication-authorization/database-administration/#access-control-database-administration-constraints[`DROP CONSTRAINT` privilege]. + +[[drop-constraint-by-name]] +== Drop a constraint by name + +A constraint can be dropped using the name with the `DROP CONSTRAINT constraint_name` command. +It is the same command for all constraint types. +The name of the constraint can be found using the xref:constraints/list-constraints.adoc[`SHOW CONSTRAINTS` command], given in the output column `name`. + +//// +The below constraints are created on constraints/create-constraints.adoc + +[source, cypher, role=test-setup] +---- +CREATE CONSTRAINT book_isbn +FOR (book:Book) REQUIRE book.isbn IS UNIQUE; +CREATE CONSTRAINT sequels +FOR ()-[sequel:SEQUEL_OF]-() REQUIRE sequel.order IS UNIQUE; +CREATE CONSTRAINT book_title_year +FOR (book:Book) REQUIRE (book.title, book.publicationYear) IS UNIQUE; +CREATE CONSTRAINT prequels +FOR ()-[prequel:PREQUEL_OF]-() REQUIRE (prequel.order, prequel.author) IS UNIQUE; +CREATE CONSTRAINT author_name +FOR (author:Author) REQUIRE author.name IS NOT NULL; +CREATE CONSTRAINT wrote_year +FOR ()-[wrote:WROTE]-() REQUIRE wrote.year IS NOT NULL; +CREATE CONSTRAINT movie_title +FOR (movie:Movie) REQUIRE movie.title IS :: STRING; +CREATE CONSTRAINT part_of +FOR ()-[part:PART_OF]-() REQUIRE part.order IS :: INTEGER; +CREATE CONSTRAINT movie_tagline +FOR (movie:Movie) REQUIRE movie.tagline IS :: STRING | LIST; +CREATE CONSTRAINT part_of_tags +FOR ()-[part:PART_OF]-() REQUIRE part.tags IS :: STRING | LIST; +CREATE CONSTRAINT director_imdbId +FOR (director:Director) REQUIRE (director.imdbId) IS NODE KEY; +CREATE CONSTRAINT ownershipId +FOR ()-[owns:OWNS]-() REQUIRE owns.ownershipId IS RELATIONSHIP KEY; +CREATE CONSTRAINT actor_fullname +FOR (actor:Actor) REQUIRE (actor.firstname, actor.surname) IS NODE KEY; +CREATE CONSTRAINT knows_since_how +FOR ()-[knows:KNOWS]-() REQUIRE (knows.since, knows.how) IS RELATIONSHIP KEY; +CREATE CONSTRAINT node_uniqueness_param +FOR (book:Book) REQUIRE book.prop1 IS UNIQUE; +CREATE CONSTRAINT rel_exist_param +FOR ()-[wrote:WROTE]-() REQUIRE wrote.published IS NOT NULL +---- +//// + +.Drop a constraint by name +====== + +.Drop the constraint `book_isbn` +// tag::schema_constraints_drop[] +[source, cypher] +---- +DROP CONSTRAINT book_isbn +---- +// end::schema_constraints_drop[] + +.Result +[source, queryresult] +---- +Removed 1 constraint. +---- + +====== + +[role=label--new-5.16] +[[drop-constraint-with-parameter]] +== Drop a constraint with a parameter + +Constraints can be dropped with a parameterized name. + +.Drop a constraint using a parameter +====== + +.Parameters +[source, parameters] +---- +{ + "name": "actor_fullname" +} +---- + +.Drop a constraint with a parameterized name +// tag::schema_constraints_drop_parameter[] +[source, cypher] +---- +DROP CONSTRAINT $name +---- +// end::schema_constraints_drop_parameter[] + +.Result +[source, queryresult] +---- +Removed 1 constraint. +---- + +====== + +[[drop-constraint-nonexisting-constraint]] +== Drop a non-existing constraint + +If it is uncertain if any constraint with a given name exists and you want to drop it if it does but not get an error should it not, use `IF EXISTS`. +This will ensure that no error is thrown. +Instead, an informational notification is returned stating that the constraint does not exist. + +.Drop a non-existing constraint +====== + +.Drop the non-existing constraint `missing_constraint_name` +[source, cypher] +---- +DROP CONSTRAINT missing_constraint_name IF EXISTS +---- + +.Result +[source, queryresult] +---- +(no changes, no records) +---- + +.Notification +[source] +---- +`DROP CONSTRAINT missing_constraint_name IF EXISTS` has no effect. `missing_constraint_name` does not exist. +---- + +====== \ No newline at end of file diff --git a/modules/ROOT/pages/constraints/index.adoc b/modules/ROOT/pages/constraints/index.adoc index e5fb8ec6c..da396de7a 100644 --- a/modules/ROOT/pages/constraints/index.adoc +++ b/modules/ROOT/pages/constraints/index.adoc @@ -1,16 +1,26 @@ -:description: Overview of Neo4j's constraints used for ensuring data integrity. +:description: Overview page for the constraints available in Cypher 5. include::https://raw.githubusercontent.com/neo4j-graphacademy/courses/main/asciidoc/courses/cypher-indexes-constraints/ad.adoc[] +:page-aliases: constraints/examples.adoc = Constraints Neo4j offers several constraints to ensure the quality and integrity of data in a graph. The following constraints are available in Neo4j: -* xref:constraints/managing-constraints.adoc#create-property-uniqueness-constraints[Property uniqueness constraints]: ensure that the combined property values are unique for all nodes with a specific label or all relationships with a specific type. -* xref:constraints/managing-constraints.adoc#create-property-existence-constraints[Property existence constraints]: ensure that a property exists either for all nodes with a specific label or for all relationships with a specific type. label:enterprise-edition[] -* xref:constraints/managing-constraints.adoc#create-property-type-constraints[Property type constraints]: ensure that a property has the required property type for all nodes with a specific label or for all relationships with a specific type. label:new[Introduced in 5.9] label:enterprise-edition[] -* xref:constraints/managing-constraints.adoc#create-key-constraints[Key constraints]: ensure that all properties exist and that the combined property values are unique for all nodes with a specific label or all relationships with a specific type.label:enterprise-edition[] +* xref:constraints/create-constraints.adoc#create-property-uniqueness-constraints[Property uniqueness constraints]: ensure that the combined property values are unique for all nodes with a specific label or all relationships with a specific type. +* xref:constraints/create-constraints.adoc#create-property-existence-constraints[Property existence constraints]: ensure that a property exists either for all nodes with a specific label or for all relationships with a specific type. label:enterprise-edition[] +* xref:constraints/create-constraints.adoc#create-property-type-constraints[Property type constraints]: ensure that a property has the required property type for all nodes with a specific label or for all relationships with a specific type. label:new[Introduced in 5.9] label:enterprise-edition[] +* xref:constraints/create-constraints.adoc#create-key-constraints[Key constraints]: ensure that all properties exist and that the combined property values are unique for all nodes with a specific label or all relationships with a specific type.label:enterprise-edition[] -To learn more about creating, listing, and dropping these constraints, as well as information about index-backed constraints, constraint creation failures and data violation scenarios, and more, see xref:constraints/managing-constraints.adoc[]. +For more information about index-backed constraints, constraint creation failures and data violation scenarios, as well as creating, listing and dropping constraints, see: -For reference material about the Cypher commands used to manage constraints, see xref:constraints/syntax.adoc[]. +* xref:constraints/create-constraints.adoc[] +* xref:constraints/list-constraints.adoc[] +* xref:constraints/drop-constraints.adoc[] +For reference material about the Cypher commands used to manage constraints, see xref:constraints/syntax.adoc#constraints[Syntax -> Constraints]. + +[TIP] +Cypher 25 includes the ability to set an open schema using graph types. +Graph types include more additional, more sophisticated constraint types and a more holistic and simplified approach for constraining and maintaining the shape of the data in a graph. +It is, therefore, recommended to define a schema using a graph type. +For more information, see the link:{neo4j-docs-base-uri}/operations-manual/25/schema/graph-types/[Cypher 25 Manual -> Graph types]. \ No newline at end of file diff --git a/modules/ROOT/pages/constraints/list-constraints.adoc b/modules/ROOT/pages/constraints/list-constraints.adoc new file mode 100644 index 000000000..3ec7c0927 --- /dev/null +++ b/modules/ROOT/pages/constraints/list-constraints.adoc @@ -0,0 +1,291 @@ +:description: Information about listing Neo4j's constraints. += Show constraints + +To list all constraints with the default output columns, use `SHOW CONSTRAINTS`. +If all columns are required, use `SHOW CONSTRAINTS YIELD *`. +For the full command syntax to list constraints, see xref:constraints/syntax.adoc#list-constraints[Syntax -> Show constraints]. +The constraints listed on this page are created on the page xref:constraints/create-constraints.adoc[]. + +One of the output columns from `SHOW CONSTRAINTS` is the name of the constraint. +This can be used to drop the constraint with the xref::constraints/drop-constraints.adoc[`DROP CONSTRAINT` command]. + +[NOTE] +Listing constraints requires the link:{neo4j-docs-base-uri}/operations-manual/current/authentication-authorization/database-administration/#access-control-database-administration-constraints[`SHOW CONSTRAINTS` privilege]. + +//// +The below constraints are created on constraints/create-constraints.adoc + +[source, cypher, role=test-setup] +---- +CREATE CONSTRAINT book_isbn +FOR (book:Book) REQUIRE book.isbn IS UNIQUE; +CREATE CONSTRAINT sequels +FOR ()-[sequel:SEQUEL_OF]-() REQUIRE sequel.order IS UNIQUE; +CREATE CONSTRAINT book_title_year +FOR (book:Book) REQUIRE (book.title, book.publicationYear) IS UNIQUE; +CREATE CONSTRAINT prequels +FOR ()-[prequel:PREQUEL_OF]-() REQUIRE (prequel.order, prequel.author) IS UNIQUE; +CREATE CONSTRAINT author_name +FOR (author:Author) REQUIRE author.name IS NOT NULL; +CREATE CONSTRAINT wrote_year +FOR ()-[wrote:WROTE]-() REQUIRE wrote.year IS NOT NULL; +CREATE CONSTRAINT movie_title +FOR (movie:Movie) REQUIRE movie.title IS :: STRING; +CREATE CONSTRAINT part_of +FOR ()-[part:PART_OF]-() REQUIRE part.order IS :: INTEGER; +CREATE CONSTRAINT movie_tagline +FOR (movie:Movie) REQUIRE movie.tagline IS :: STRING | LIST; +CREATE CONSTRAINT part_of_tags +FOR ()-[part:PART_OF]-() REQUIRE part.tags IS :: STRING | LIST; +CREATE CONSTRAINT director_imdbId +FOR (director:Director) REQUIRE (director.imdbId) IS NODE KEY; +CREATE CONSTRAINT ownershipId +FOR ()-[owns:OWNS]-() REQUIRE owns.ownershipId IS RELATIONSHIP KEY; +CREATE CONSTRAINT actor_fullname +FOR (actor:Actor) REQUIRE (actor.firstname, actor.surname) IS NODE KEY; +CREATE CONSTRAINT knows_since_how +FOR ()-[knows:KNOWS]-() REQUIRE (knows.since, knows.how) IS RELATIONSHIP KEY; +CREATE CONSTRAINT node_uniqueness_param +FOR (book:Book) REQUIRE book.prop1 IS UNIQUE; +CREATE CONSTRAINT rel_exist_param +FOR ()-[wrote:WROTE]-() REQUIRE wrote.published IS NOT NULL +---- +//// + +.List all constraints with default output columns +====== + +.Query +// tag::schema_constraints_show[] +[source, cypher, test-exclude-cols=id] +---- +SHOW CONSTRAINTS +---- +// end::schema_constraints_show[] + +.Result +[source, queryresult] +---- ++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| id | name | type | entityType | labelsOrTypes | properties | ownedIndex | propertyType | ++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| 10 | "actor_fullname" | "NODE_KEY" | "NODE" | ["Actor"] | ["firstname", "surname"] | "actor_fullname" | NULL | +| 20 | "author_name" | "NODE_PROPERTY_EXISTENCE" | "NODE" | ["Author"] | ["name"] | NULL | NULL | +| 63 | "book_isbn" | "UNIQUENESS" | "NODE" | ["Book"] | ["isbn"] | "book_isbn" | NULL | +| 3 | "book_title_year" | "UNIQUENESS" | "NODE" | ["Book"] | ["title", "publicationYear"] | "book_title_year" | NULL | +| 13 | "director_imdbId" | "NODE_KEY" | "NODE" | ["Director"] | ["imdbId"] | "director_imdbId" | NULL | +| 41 | "knows_since_how" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["KNOWS"] | ["since", "how"] | "knows_since_how" | NULL | +| 25 | "movie_tagline" | "NODE_PROPERTY_TYPE" | "NODE" | ["Movie"] | ["tagline"] | NULL | "STRING | LIST" | +| 7 | "movie_title" | "NODE_PROPERTY_TYPE" | "NODE" | ["Movie"] | ["title"] | NULL | "STRING" | +| 28 | "node_uniqueness_param" | "UNIQUENESS" | "NODE" | ["Book"] | ["prop1"] | "node_uniqueness_param" | NULL | +| 38 | "ownershipId" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["OWNS"] | ["ownershipId"] | "ownershipId" | NULL | +| 44 | "part_of" | "RELATIONSHIP_PROPERTY_TYPE" | "RELATIONSHIP" | ["PART_OF"] | ["order"] | NULL | "INTEGER" | +| 24 | "part_of_tags" | "RELATIONSHIP_PROPERTY_TYPE" | "RELATIONSHIP" | ["PART_OF"] | ["tags"] | NULL | "STRING | LIST" | +| 4 | "prequels" | "RELATIONSHIP_UNIQUENESS" | "RELATIONSHIP" | ["PREQUEL_OF"] | ["order", "author"] | "prequels" | NULL | +| 42 | "rel_exist_param" | "RELATIONSHIP_PROPERTY_EXISTENCE" | "RELATIONSHIP" | ["WROTE"] | ["published"] | NULL | NULL | +| 65 | "sequels" | "RELATIONSHIP_UNIQUENESS" | "RELATIONSHIP" | ["SEQUEL_OF"] | ["order"] | "sequels" | NULL | +| 22 | "wrote_year" | "RELATIONSHIP_PROPERTY_EXISTENCE" | "RELATIONSHIP" | ["WROTE"] | ["year"] | NULL | NULL | ++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +---- + +====== + +.List all constraints with full details +====== + +To return the full details of the constraints on a database, use `SHOW CONSTRAINTS YIELD *` + +.List all constraints with `YIELD *` +// tag::schema_constraints_show_full[] +[source, cypher, test-exclude-cols=id] +---- +SHOW CONSTRAINTS YIELD * +---- +// end::schema_constraints_show_full[] + +.Result +[source, queryresult] +---- ++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| id | name | type | entityType | labelsOrTypes | properties | ownedIndex | propertyType | options | createStatement | ++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| 10 | "actor_fullname" | "NODE_KEY" | "NODE" | ["Actor"] | ["firstname", "surname"] | "actor_fullname" | NULL | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `actor_fullname` FOR (n:`Actor`) REQUIRE (n.`firstname`, n.`surname`) IS NODE KEY" | +| 20 | "author_name" | "NODE_PROPERTY_EXISTENCE" | "NODE" | ["Author"] | ["name"] | NULL | NULL | NULL | "CREATE CONSTRAINT `author_name` FOR (n:`Author`) REQUIRE (n.`name`) IS NOT NULL" | +| 63 | "book_isbn" | "UNIQUENESS" | "NODE" | ["Book"] | ["isbn"] | "book_isbn" | NULL | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `book_isbn` FOR (n:`Book`) REQUIRE (n.`isbn`) IS UNIQUE" | +| 3 | "book_title_year" | "UNIQUENESS" | "NODE" | ["Book"] | ["title", "publicationYear"] | "book_title_year" | NULL | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `book_title_year` FOR (n:`Book`) REQUIRE (n.`title`, n.`publicationYear`) IS UNIQUE" | +| 13 | "director_imdbId" | "NODE_KEY" | "NODE" | ["Director"] | ["imdbId"] | "director_imdbId" | NULL | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `director_imdbId` FOR (n:`Director`) REQUIRE (n.`imdbId`) IS NODE KEY" | +| 41 | "knows_since_how" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["KNOWS"] | ["since", "how"] | "knows_since_how" | NULL | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `knows_since_how` FOR ()-[r:`KNOWS`]-() REQUIRE (r.`since`, r.`how`) IS RELATIONSHIP KEY" | +| 25 | "movie_tagline" | "NODE_PROPERTY_TYPE" | "NODE" | ["Movie"] | ["tagline"] | NULL | "STRING | LIST" | NULL | "CREATE CONSTRAINT `movie_tagline` FOR (n:`Movie`) REQUIRE (n.`tagline`) IS :: STRING | LIST" | +| 7 | "movie_title" | "NODE_PROPERTY_TYPE" | "NODE" | ["Movie"] | ["title"] | NULL | "STRING" | NULL | "CREATE CONSTRAINT `movie_title` FOR (n:`Movie`) REQUIRE (n.`title`) IS :: STRING" | +| 28 | "node_uniqueness_param" | "UNIQUENESS" | "NODE" | ["Book"] | ["prop1"] | "node_uniqueness_param" | NULL | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `node_uniqueness_param` FOR (n:`Book`) REQUIRE (n.`prop1`) IS UNIQUE" | +| 38 | "ownershipId" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["OWNS"] | ["ownershipId"] | "ownershipId" | NULL | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `ownershipId` FOR ()-[r:`OWNS`]-() REQUIRE (r.`ownershipId`) IS RELATIONSHIP KEY" | +| 44 | "part_of" | "RELATIONSHIP_PROPERTY_TYPE" | "RELATIONSHIP" | ["PART_OF"] | ["order"] | NULL | "INTEGER" | NULL | "CREATE CONSTRAINT `part_of` FOR ()-[r:`PART_OF`]-() REQUIRE (r.`order`) IS :: INTEGER" | +| 24 | "part_of_tags" | "RELATIONSHIP_PROPERTY_TYPE" | "RELATIONSHIP" | ["PART_OF"] | ["tags"] | NULL | "STRING | LIST" | NULL | "CREATE CONSTRAINT `part_of_tags` FOR ()-[r:`PART_OF`]-() REQUIRE (r.`tags`) IS :: STRING | LIST" | +| 4 | "prequels" | "RELATIONSHIP_UNIQUENESS" | "RELATIONSHIP" | ["PREQUEL_OF"] | ["order", "author"] | "prequels" | NULL | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `prequels` FOR ()-[r:`PREQUEL_OF`]-() REQUIRE (r.`order`, r.`author`) IS UNIQUE" | +| 42 | "rel_exist_param" | "RELATIONSHIP_PROPERTY_EXISTENCE" | "RELATIONSHIP" | ["WROTE"] | ["published"] | NULL | NULL | NULL | "CREATE CONSTRAINT `rel_exist_param` FOR ()-[r:`WROTE`]-() REQUIRE (r.`published`) IS NOT NULL" | +| 65 | "sequels" | "RELATIONSHIP_UNIQUENESS" | "RELATIONSHIP" | ["SEQUEL_OF"] | ["order"] | "sequels" | NULL | {indexConfig: {}, indexProvider: "range-1.0"} | "CREATE CONSTRAINT `sequels` FOR ()-[r:`SEQUEL_OF`]-() REQUIRE (r.`order`) IS UNIQUE" | +| 22 | "wrote_year" | "RELATIONSHIP_PROPERTY_EXISTENCE" | "RELATIONSHIP" | ["WROTE"] | ["year"] | NULL | NULL | NULL | "CREATE CONSTRAINT `wrote_year` FOR ()-[r:`WROTE`]-() REQUIRE (r.`year`) IS NOT NULL" | ++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +---- +====== + +[[list-constraints-with-filtering]] +== Listing constraints with filtering + +The `SHOW CONSTRAINTS` command can be filtered in various ways. +The filtering of rows can be done using constraint type keywords or a `WHERE` clause, while filtering of columns is achieved by specifying the desired columns in a `YIELD` clause. + +.List only specific constraint types +====== + +.List only key constraints +// tag::schema_constraints_show_type_filter[] +[source, cypher, test-exclude-cols=id] +---- +SHOW KEY CONSTRAINTS +---- +// end::schema_constraints_show_type_filter[] + +.Result +[source, queryresult] +---- ++------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| id | name | type | entityType | labelsOrTypes | properties | enforcedLabel | ownedIndex | propertyType | ++------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| 28 | "actor_fullname" | "NODE_KEY" | "NODE" | ["Actor"] | ["firstname", "surname"] | NULL | "actor_fullname" | NULL | +| 36 | "director_imdbId" | "NODE_KEY" | "NODE" | ["Director"] | ["imdbId"] | NULL | "director_imdbId" | NULL | +| 26 | "knows_since_how" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["KNOWS"] | ["since", "how"] | NULL | "knows_since_how" | NULL | +| 38 | "ownershipId" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["OWNS"] | ["ownershipId"] | NULL | "ownershipId" | NULL | ++------------------------------------------------------------------------------------------------------------------------------------------------------------+ +---- + +For a full list of all the constraint types (and synonyms) available in this command see xref:constraints/syntax.adoc#list-constraints[Syntax -> SHOW CONSTRAINTS]. + +====== + + +.Filtering constraints using the `WHERE` clause +====== + +.List only constraints with a `RELATIONSHIP` `entityType` +[source, cypher, test-exclude-cols=id] +---- +SHOW CONSTRAINTS +WHERE entityType = 'RELATIONSHIP' +---- + +.Result +[source, queryresult] +---- ++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| id | name | type | entityType | labelsOrTypes | properties | ownedIndex | propertyType | ++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| 41 | "knows_since_how" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["KNOWS"] | ["since", "how"] | "knows_since_how" | NULL | +| 38 | "ownershipId" | "RELATIONSHIP_KEY" | "RELATIONSHIP" | ["OWNS"] | ["ownershipId"] | "ownershipId" | NULL | +| 44 | "part_of" | "RELATIONSHIP_PROPERTY_TYPE" | "RELATIONSHIP" | ["PART_OF"] | ["order"] | NULL | "INTEGER" | +| 24 | "part_of_tags" | "RELATIONSHIP_PROPERTY_TYPE" | "RELATIONSHIP" | ["PART_OF"] | ["tags"] | NULL | "STRING | LIST" | +| 4 | "prequels" | "RELATIONSHIP_UNIQUENESS" | "RELATIONSHIP" | ["PREQUEL_OF"] | ["order", "author"] | "prequels" | NULL | +| 42 | "rel_exist_param" | "RELATIONSHIP_PROPERTY_EXISTENCE" | "RELATIONSHIP" | ["WROTE"] | ["published"] | NULL | NULL | +| 65 | "sequels" | "RELATIONSHIP_UNIQUENESS" | "RELATIONSHIP" | ["SEQUEL_OF"] | ["order"] | "sequels" | NULL | +| 22 | "wrote_year" | "RELATIONSHIP_PROPERTY_EXISTENCE" | "RELATIONSHIP" | ["WROTE"] | ["year"] | NULL | NULL | ++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +---- + +====== + + +.Returning specific columns for all constraints +====== + +It is possible to return only specific columns of the available constraints using the `YIELD` clause: + +.List only the `name`, `type`, and `createStatement` columns +// tag::schema_constraints_show_specific_columns[] +[source, cypher, test-exclude-cols=id] +---- +SHOW CONSTRAINTS +YIELD name, type, createStatement +---- +// end::schema_constraints_show_specific_columns[] + +.Result +[source, queryresult] +---- ++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| name | type | createStatement | ++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| "actor_fullname" | "NODE_KEY" | "CREATE CONSTRAINT `actor_fullname` FOR (n:`Actor`) REQUIRE (n.`firstname`, n.`surname`) IS NODE KEY" | +| "author_name" | "NODE_PROPERTY_EXISTENCE" | "CREATE CONSTRAINT `author_name` FOR (n:`Author`) REQUIRE (n.`name`) IS NOT NULL" | +| "book_isbn" | "UNIQUENESS" | "CREATE CONSTRAINT `book_isbn` FOR (n:`Book`) REQUIRE (n.`isbn`) IS UNIQUE" | +| "book_title_year" | "UNIQUENESS" | "CREATE CONSTRAINT `book_title_year` FOR (n:`Book`) REQUIRE (n.`title`, n.`publicationYear`) IS UNIQUE" | +| "director_imdbId" | "NODE_KEY" | "CREATE CONSTRAINT `director_imdbId` FOR (n:`Director`) REQUIRE (n.`imdbId`) IS NODE KEY" | +| "knows_since_how" | "RELATIONSHIP_KEY" | "CREATE CONSTRAINT `knows_since_how` FOR ()-[r:`KNOWS`]-() REQUIRE (r.`since`, r.`how`) IS RELATIONSHIP KEY" | +| "movie_tagline" | "NODE_PROPERTY_TYPE" | "CREATE CONSTRAINT `movie_tagline` FOR (n:`Movie`) REQUIRE (n.`tagline`) IS :: STRING | LIST" | +| "movie_title" | "NODE_PROPERTY_TYPE" | "CREATE CONSTRAINT `movie_title` FOR (n:`Movie`) REQUIRE (n.`title`) IS :: STRING" | +| "node_uniqueness_param" | "UNIQUENESS" | "CREATE CONSTRAINT `node_uniqueness_param` FOR (n:`Book`) REQUIRE (n.`prop1`) IS UNIQUE" | +| "ownershipId" | "RELATIONSHIP_KEY" | "CREATE CONSTRAINT `ownershipId` FOR ()-[r:`OWNS`]-() REQUIRE (r.`ownershipId`) IS RELATIONSHIP KEY" | +| "part_of" | "RELATIONSHIP_PROPERTY_TYPE" | "CREATE CONSTRAINT `part_of` FOR ()-[r:`PART_OF`]-() REQUIRE (r.`order`) IS :: INTEGER" | +| "part_of_tags" | "RELATIONSHIP_PROPERTY_TYPE" | "CREATE CONSTRAINT `part_of_tags` FOR ()-[r:`PART_OF`]-() REQUIRE (r.`tags`) IS :: STRING | LIST" | +| "prequels" | "RELATIONSHIP_UNIQUENESS" | "CREATE CONSTRAINT `prequels` FOR ()-[r:`PREQUEL_OF`]-() REQUIRE (r.`order`, r.`author`) IS UNIQUE" | +| "rel_exist_param" | "RELATIONSHIP_PROPERTY_EXISTENCE" | "CREATE CONSTRAINT `rel_exist_param` FOR ()-[r:`WROTE`]-() REQUIRE (r.`published`) IS NOT NULL" | +| "sequels" | "RELATIONSHIP_UNIQUENESS" | "CREATE CONSTRAINT `sequels` FOR ()-[r:`SEQUEL_OF`]-() REQUIRE (r.`order`) IS UNIQUE" | +| "wrote_year" | "RELATIONSHIP_PROPERTY_EXISTENCE" | "CREATE CONSTRAINT `wrote_year` FOR ()-[r:`WROTE`]-() REQUIRE (r.`year`) IS NOT NULL" | ++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +---- + +====== + + +[[list-constraints-result-columns]] +== Result columns for listing constraints + +.Listing constraints output +[options="header", width="100%", cols="4m,6a,2m"] +|=== +| Column | Description | Type + +| id +| The id of the constraint. label:default-output[] +| INTEGER + +| name +| Name of the constraint (explicitly set by the user or automatically assigned). label:default-output[] +| STRING + +| type +| The ConstraintType of this constraint (`NODE_PROPERTY_UNIQUENESS`, `RELATIONSHIP_PROPERTY_UNIQUENESS`, `NODE_PROPERTY_EXISTENCE`, `RELATIONSHIP_PROPERTY_EXISTENCE`, `NODE_PROPERTY_TYPE`, `RELATIONSHIP_PROPERTY_TYPE`, `NODE_LABEL_EXISTENCE`, `RELATIONSHIP_SOURCE_LABEL`, `RELATIONSHIP_TARGET_LABEL`, `NODE_KEY`, or `RELATIONSHIP_KEY`). label:default-output[] + +| STRING + +| entityType +| Type of entities this constraint represents (`NODE` or `RELATIONSHIP`). label:default-output[] +| STRING + +| labelsOrTypes +| The labels or relationship types of this constraint. +The list returned will only include a single value (the name of the constrained node label or relationship type). label:default-output[] +| LIST + +| properties +| The properties of this constraint, or `null` for node label existence, relationship source label, and relationship target constraints which do not constrain properties (these constraints are created as part of node and relationship element types when setting a graph type (only available in Cypher 25). For more information see the link:{neo4j-docs-base-uri}/operations-manual/25/schema/graph-types[Cypher 25 Manual -> Graph types]). label:default-output[] +| LIST + +| ownedIndex +| The name of the index associated with the constraint or `null`, in case no index is associated with it. label:default-output[] +| STRING + +| propertyType +| The property type the property is restricted to for property type constraints, or `null` for the other constraints. +label:default-output[] label:new[Introduced in 5.9] +| STRING + +| options +| The options passed to `CREATE` command, for the index associated to the constraint, or `null` if no index is associated with the constraint. +| MAP + +| createStatement +| Statement used to create the constraint, or `null` for constraints with `dependent` classification. +For more information, see the link:{neo4j-docs-base-uri}/operations-manual/25/schema/graph-types/list-graph-types/#graph-type-elements-in-show-constraints[Cypher 25 Manual -> Graph type elements in `SHOW CONSTRAINTS`]. +| STRING + +|=== diff --git a/modules/ROOT/pages/constraints/syntax.adoc b/modules/ROOT/pages/constraints/syntax.adoc index 321776373..77c2a2b65 100644 --- a/modules/ROOT/pages/constraints/syntax.adoc +++ b/modules/ROOT/pages/constraints/syntax.adoc @@ -1,15 +1,10 @@ :description: Syntax for how to manage constraints used for ensuring data integrity. - -[[constraints-syntax]] = Syntax -:check-mark: icon:check[] This page contains the syntax for creating, listing, and dropping the constraints available in Neo4j. -More details about the syntax can be found in the link:{neo4j-docs-base-uri}/operations-manual/current/database-administration/syntax/[Operations Manual -> Cypher syntax for administration commands]. - -[[constraints-syntax-create]] -== CREATE CONSTRAINT +[[create-constraint]] +== Create constraints Constraints are created with the `CREATE CONSTRAINT` command. When creating a constraint, it is recommended to provide a constraint name. @@ -24,7 +19,7 @@ This means its default behavior is to throw an error if an attempt is made to cr With the `IF NOT EXISTS` flag, no error is thrown and nothing happens should a constraint with the same name or same schema and constraint type already exist. It may still throw an error if conflicting data, indexes, or constraints exist. Examples of this are nodes with missing properties, indexes with the same name, or constraints with same schema but a different conflicting constraint type. -As of Neo4j 5.17, an informational notification is returned in case nothing happens showing the existing constraint which blocks the creation. +An informational notification is returned in case nothing happens showing the existing constraint which blocks the creation. [[create-property-uniqueness-constraints]] === Create property uniqueness constraints @@ -61,8 +56,8 @@ FOR ()-"["r:RELATIONSHIP_TYPE"]"-() REQUIRE (r.propertyName_1, ..., r.propertyName_n) IS [REL[ATIONSHIP]] UNIQUE ---- -For examples on how to create property uniqueness constraints, see xref:constraints/managing-constraints.adoc#create-property-uniqueness-constraints[Create, show, and drop constraints -> Create property uniqueness constraint]. -Property uniqueness constraints are xref:constraints/managing-constraints.adoc#constraints-and-indexes[index-backed]. +For examples on how to create property uniqueness constraints, see xref:constraints/create-constraints.adoc#create-property-uniqueness-constraints[Create constraints -> Create property uniqueness constraint]. +Property uniqueness constraints are xref:constraints/create-constraints.adoc#constraints-and-indexes[index-backed]. [role=label--enterprise-edition] [[create-property-existence-constraints]] @@ -84,7 +79,7 @@ FOR ()-"["r:RELATIONSHIP_TYPE"]"-() REQUIRE r.propertyName IS NOT NULL ---- -For examples on how to create property existence constraints, see xref:constraints/managing-constraints.adoc#create-property-existence-constraints[Create, show, and drop constraints -> Create property existence constraints]. +For examples on how to create property existence constraints, see xref:constraints/create-constraints.adoc#create-property-existence-constraints[Create constraints -> Create property existence constraints]. [role=label--enterprise-edition label--new-5.9] [[create-property-type-constraints]] @@ -137,7 +132,7 @@ Where `` is one of the following property types: Allowed syntax variations of these types are listed in xref::values-and-types/property-structural-constructed.adoc#types-synonyms[Types and their synonyms]. -For examples on how to create property type constraints, see xref:constraints/managing-constraints.adoc#create-property-type-constraints[Create, show, and drop constraints -> Create property type constraints]. +For examples on how to create property type constraints, see xref:constraints/create-constraints.adoc#create-property-type-constraints[Create constraints -> Create property type constraints]. [role=label--enterprise-edition] @@ -176,12 +171,11 @@ FOR ()-"["r:RELATIONSHIP_TYPE"]"-() REQUIRE (r.propertyName_1, ..., r.propertyName_n) IS [REL[ATIONSHIP]] KEY ---- -For examples on how to create key constraints, see xref:constraints/managing-constraints.adoc#create-key-constraints[Create, show, and drop constraints -> Create key constraints]. -Key constraints are xref:constraints/managing-constraints.adoc#constraints-and-indexes[index-backed]. - +For examples on how to create key constraints, see xref:constraints/create-constraints.adoc#create-key-constraints[Create constraints -> Create key constraints]. +Key constraints are xref:constraints/create-constraints.adoc#constraints-and-indexes[index-backed]. [[list-constraints]] -== SHOW CONSTRAINTS +== Show constraints To list all constraints with the default output columns, use `SHOW CONSTRAINTS`. If all columns are required, use `SHOW CONSTRAINTS YIELD *`. @@ -191,15 +185,14 @@ The `SHOW CONSTRAINTS` clause can also be filtered using the xref:clauses/where. [NOTE] Listing constraints requires the link:{neo4j-docs-base-uri}/operations-manual/current/authentication-authorization/database-administration/#access-control-database-administration-constraints[`SHOW CONSTRAINTS` privilege]. - .Syntax to list constraints with default return columns [source, syntax] ---- SHOW [ ALL - |NODE UNIQUE[NESS] - |REL[ATIONSHIP] UNIQUE[NESS] - |UNIQUE[NESS] + |NODE [PROPERTY] UNIQUE[NESS] + |REL[ATIONSHIP] [PROPERTY] UNIQUE[NESS] + |[PROPERTY] UNIQUE[NESS] |NODE [PROPERTY] EXIST[ENCE] |REL[ATIONSHIP] [PROPERTY] EXIST[ENCE] |[PROPERTY] EXIST[ENCE] @@ -218,9 +211,9 @@ SHOW [ ---- SHOW [ ALL - |NODE UNIQUE[NESS] - |REL[ATIONSHIP] UNIQUE[NESS] - |UNIQUE[NESS] + |NODE [PROPERTY] UNIQUE[NESS] + |REL[ATIONSHIP] [PROPERTY] UNIQUE[NESS] + |[PROPERTY] UNIQUE[NESS] |NODE [PROPERTY] EXIST[ENCE] |REL[ATIONSHIP] [PROPERTY] EXIST[ENCE] |[PROPERTY] EXIST[ENCE] @@ -244,69 +237,77 @@ The type filtering keywords filters the returned constraints on constraint type: |=== | Filter | Description -|ALL +| ALL | Returns all constraints, no filtering on constraint type. This is the default if none is given. -|NODE UNIQUE[NESS] -| Returns the node property uniqueness constraints. +| NODE UNIQUE[NESS] +| Returns node property uniqueness constraints. label:new[Introduced in 5.7] -|REL[ATIONSHIP] UNIQUE[NESS] -| Returns the relationship property uniqueness constraints. +| REL[ATIONSHIP] UNIQUE[NESS] +| Returns relationship property uniqueness constraints. label:new[Introduced in 5.7] -|UNIQUE[NESS] +| UNIQUE[NESS] | Returns all property uniqueness constraints, for both nodes and relationships. label:new[Allowing `UNIQUENESS` was introduced in 5.3] -|NODE [PROPERTY] EXIST[ENCE] -| Returns the node property existence constraints. +| NODE PROPERTY EXIST[ENCE] +| Returns node property existence constraints. -|REL[ATIONSHIP] [PROPERTY] EXIST[ENCE] -| Returns the relationship property existence constraints. +| REL[ATIONSHIP] PROPERTY EXIST[ENCE] +| Returns relationship property existence constraints. -|[PROPERTY] EXIST[ENCE] -| Returns all property existence constraints, for both nodes and relationships. +| PROPERTY EXIST[ENCE] +| Returns property existence constraints, for both nodes and relationships. -|NODE PROPERTY TYPE -| Returns the node property type constraints. +| NODE EXIST[ENCE] +| Returns node existence constraints. + +| REL[ATIONSHIP] EXIST[ENCE] +| Returns relationship existence constraints. + +| EXIST[ENCE] +| Returns existence constraints, for both nodes and relationships. + +| NODE PROPERTY TYPE +| Returns node property type constraints. label:new[Introduced in 5.9] -|REL[ATIONSHIP] PROPERTY TYPE -| Returns the relationship property type constraints. +| REL[ATIONSHIP] PROPERTY TYPE +| Returns relationship property type constraints. label:new[Introduced in 5.9] -|PROPERTY TYPE -| Returns all property type constraints, for both nodes and relationships. +| PROPERTY TYPE +| Returns property type constraints, for both nodes and relationships. label:new[Introduced in 5.9] -|NODE KEY -| Returns the node key constraints. +| NODE KEY +| Returns node key constraints. -|REL[ATIONSHIP] KEY -| Returns the relationship key constraints. +| REL[ATIONSHIP] KEY +| Returns relationship key constraints. label:new[Introduced in 5.7] -|KEY -| Returns all node and relationship key constraints. +| KEY +| Returns key constraints, for both nodes and relationships. label:new[Introduced in 5.7] |=== -For examples on how to list constraints, see xref:constraints/managing-constraints.adoc#list-constraints[Create, show, and drop constraints -> SHOW CONSTRAINTS]. -For full details of the result columns for the `SHOW CONSTRAINTS` command, see xref:constraints/managing-constraints.adoc#list-constraints-result-columns[Create, show, and drop constraints -> Result columns for listing constraints]. +For examples on how to list constraints, see xref:constraints/list-constraints.adoc[Show constraints]. +For full details of the result columns for the `SHOW CONSTRAINTS` command, see xref:constraints/list-constraints.adoc#list-constraints-result-columns[Show constraints -> Result columns for listing constraints]. [[drop-constraint]] -== DROP CONSTRAINT +== Drop constraints -Constraints are dropped using the `DROP` CONSTRAINT command. +Constraints are dropped using the `DROP` CONSTRAINT` command. Dropping a constraint is done by specifying the name of the constraint. [NOTE] Dropping a constraint requires the link:{neo4j-docs-base-uri}/operations-manual/current/authentication-authorization/database-administration/#access-control-database-administration-constraints[`DROP CONSTRAINT` privilege]. - .Syntax for dropping a constraint by name [source, syntax] ---- @@ -316,6 +317,6 @@ DROP CONSTRAINT constraint_name [IF EXISTS] This command is optionally idempotent. This means its default behavior is to throw an error if an attempt is made to drop the same constraint twice. With the `IF EXISTS` flag, no error is thrown and nothing happens should the constraint not exist. -As of Neo4j 5.17, an informational notification is instead returned detailing that the constraint does not exist. +Instead, an informational notification is returned detailing that the constraint does not exist. -For examples on how to drop constraints, see xref:constraints/managing-constraints.adoc#drop-constraint[Create, show, and drop constraints -> DROP CONSTRAINT]. +For examples on how to drop constraints, see xref:constraints/drop-constraints.adoc[Drop constraints]. \ No newline at end of file diff --git a/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc b/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc index 33c835da7..9736912d3 100644 --- a/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc +++ b/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc @@ -28,6 +28,42 @@ For more information, see: * link:https://neo4j.com/docs/cypher-manual/25/introduction/[Cypher 25 Manual] ==== +[[cypher-deprecations-additions-removals-2025.xx]] +== Neo4j 2025.xx + +=== Updated in Cypher 5 + +[cols="2", options="header"] +|=== +| Feature +| Details + +a| +label:functionality[] +label:updated[] +[source, syntax, role="noheader"] +---- +SHOW [NODE] EXIST[ENCE] CONSTRAINTS +---- + +| The `NODE EXIST[ENCE]` and `EXIST[ENCE]` type filtering options allowed by the `SHOW CONSTRAINTS` command now also return node label existence constraints (crated as part of node element types in a link:{neo4j-docs-base-uri}/operations-manual/25/schema/graph-types/[graph type] (only available in Cypher 25)). +For more information, see xref:constraints/syntax.adoc#constraints-syntax-list-type-filter[Syntax -> Type filters]. + +a| +label:functionality[] +label:updated[] +[source, syntax, role="noheader"] +---- +SHOW CONSTRAINTS +---- + +a| The `type` column returned by xref:constraints/list-constraints.adoc[`SHOW CONSTRAINTS`] can now return three additional constraint types: `NODE_LABEL_EXISTENCE`, `RELATIONSHIP_SOURCE_LABEL` and `RELATIONSHIP_TARGET_LABEL`. +These new constraint types are created as part of node and relationship element types when setting a graph type (only available in Cypher 25). +For more information, see the link:{neo4j-docs-base-uri}/operations-manual/25/schema/graph-types/[Cypher 25 Manual -> Graph types]. + +|=== + + [[cypher-deprecations-additions-removals-2025.09]] == Neo4j 2025.09 @@ -1763,7 +1799,7 @@ CREATE CONSTRAINT name FOR ()-[r:TYPE]-() REQUIRE r.prop IS :: ---- a| -Extended xref::constraints/managing-constraints.adoc#create-property-type-constraint-union-type[node and relationship property type constraints]. +Extended xref::constraints/create-constraints.adoc#create-property-type-constraint-union-type[node and relationship property type constraints]. Closed dynamic union types (`type1 \| type2 \| ...`) are now supported, allowing for types such as: * `INTEGER \| FLOAT` @@ -1845,7 +1881,7 @@ CREATE CONSTRAINT name FOR ()-[r:TYPE]-() REQUIRE r.prop IS :: ---- a| -Extended xref::constraints/managing-constraints.adoc#type-constraints-allowed-properties[node and relationship property type constraints]. +Extended xref::constraints/create-constraints.adoc#type-constraints-allowed-properties[node and relationship property type constraints]. The new supported types are: * `LIST` @@ -2003,7 +2039,7 @@ CREATE CONSTRAINT name FOR ()-[r:TYPE]-() REQUIRE r.prop IS :: ---- a| -Added xref::constraints/managing-constraints.adoc#create-property-type-constraints[node and relationship property type constraints]. +Added xref::constraints/create-constraints.adoc#create-property-type-constraints[node and relationship property type constraints]. The available property types are: * `BOOLEAN` @@ -2153,7 +2189,7 @@ CREATE CONSTRAINT name FOR ()-[r:TYPE]-() REQUIRE r.prop IS RELATIONSHIP KEY ---- a| -Added relationship xref:constraints/managing-constraints.adoc#create-key-constraints[key] and xref:constraints/managing-constraints.adoc#create-property-uniqueness-constraints[property uniqueness] constraints. +Added relationship xref:constraints/create-constraints.adoc#create-key-constraints[key] and xref:constraints/create-constraints.adoc#create-property-uniqueness-constraints[property uniqueness] constraints. a| label:functionality[] diff --git a/modules/ROOT/pages/indexes/search-performance-indexes/managing-indexes.adoc b/modules/ROOT/pages/indexes/search-performance-indexes/managing-indexes.adoc index cc7b113a7..2b7e7512e 100644 --- a/modules/ROOT/pages/indexes/search-performance-indexes/managing-indexes.adoc +++ b/modules/ROOT/pages/indexes/search-performance-indexes/managing-indexes.adoc @@ -235,7 +235,7 @@ However, other predicates are only used when it is known that the property is co * `n.prop = "string"` * `n.prop IN ["a", "b", "c"]` -This means that a text index is not able to solve, for example, e.g. `a.prop = b.prop`, unless a xref:constraints/managing-constraints.adoc#create-property-type-constraints[property type constraint] also exists on the property. +This means that a text index is not able to solve, for example, e.g. `a.prop = b.prop`, unless a xref:constraints/create-constraints.adoc#create-property-type-constraints[property type constraint] also exists on the property. Text indexes support the following predicates: @@ -1101,7 +1101,7 @@ Unable to drop index: Index belongs to constraint: `uniqueBookIsbn` ---- Dropping the index-backed constraint will also remove the backing index. -For more information, see xref:constraints/managing-constraints.adoc#drop-constraint[Drop a constraint by name]. +For more information, see xref:constraints/create-constraints.adoc#drop-constraint[Drop a constraint by name]. [discrete] [[drop-a-non-existing-index]] diff --git a/modules/ROOT/pages/indexes/search-performance-indexes/using-indexes.adoc b/modules/ROOT/pages/indexes/search-performance-indexes/using-indexes.adoc index 6312ac73d..2cce67ad6 100644 --- a/modules/ROOT/pages/indexes/search-performance-indexes/using-indexes.adoc +++ b/modules/ROOT/pages/indexes/search-performance-indexes/using-indexes.adoc @@ -897,7 +897,7 @@ The xref:functions/string.adoc#functions-tostring[`toString`] function can also For indexes that are compatible only with specific types (i.e. text and point indexes), the Cypher planner needs to deduce that a predicate will evaluate to `null` for non-compatible values in order to use the index. If a predicate is not explicitly defined as the required type (`STRING` or `POINT`), this can lead to situations where a text or point index is not used. -Since xref:constraints/managing-constraints.adoc#create-property-type-constraints[property type constraints] guarantee that a property is always of the same type, they can be used to extend the scenarios in which text and point indexes are compatible with a predicate. +Since xref:constraints/create-constraints.adoc#create-property-type-constraints[property type constraints] guarantee that a property is always of the same type, they can be used to extend the scenarios in which text and point indexes are compatible with a predicate. To show this, the following example will first drop the existing range index on the `name` property (this is necessary because property type constraints only extend the compatibility of type-specific indexes - range indexes are not limited by a value type). It will then run the same query with a `WHERE` predicate on the `name` property (for which there exists a previously created text index) before and after creating a property type constraint, and compare the resulting execution plans. @@ -976,7 +976,7 @@ Because of the property type constraint on the `name` property, the planner is n Point indexes can be extended in the same way if a property type constraint is created to ensure that all properties are `POINT` values. -Note that xref:constraints/managing-constraints.adoc#create-property-existence-constraints[property existence constraints] do not currently leverage index use in the same way. +Note that xref:constraints/create-constraints.adoc#create-property-existence-constraints[property existence constraints] do not currently leverage index use in the same way. [[Heuristics]] == Heuristics: deciding what to index diff --git a/modules/ROOT/pages/introduction/cypher-neo4j.adoc b/modules/ROOT/pages/introduction/cypher-neo4j.adoc index 76d52810d..a1b93d4d9 100644 --- a/modules/ROOT/pages/introduction/cypher-neo4j.adoc +++ b/modules/ROOT/pages/introduction/cypher-neo4j.adoc @@ -32,12 +32,12 @@ All users have full access rights. | Constraints a| All constraints: -xref::constraints/managing-constraints.adoc#create-property-existence-constraints[node and relationship property existence constraints], -xref::constraints/managing-constraints.adoc#create-property-type-constraints[node and relationship property type constraints], -xref::constraints/managing-constraints.adoc#create-property-uniqueness-constraints[node and relationship property uniqueness constraints], -xref::constraints/managing-constraints.adoc#create-key-constraints[node and relationship key constraints]. +xref::constraints/create-constraints.adoc#create-property-existence-constraints[node and relationship property existence constraints], +xref::constraints/create-constraints.adoc#create-property-type-constraints[node and relationship property type constraints], +xref::constraints/create-constraints.adoc#create-property-uniqueness-constraints[node and relationship property uniqueness constraints], +xref::constraints/create-constraints.adoc#create-key-constraints[node and relationship key constraints]. a| -Only xref::constraints/managing-constraints.adoc#create-property-uniqueness-constraints[node and relationship property uniqueness constraints]. +Only xref::constraints/create-constraints.adoc#create-property-uniqueness-constraints[node and relationship property uniqueness constraints]. | Runtimes a| diff --git a/modules/ROOT/pages/introduction/cypher-overview.adoc b/modules/ROOT/pages/introduction/cypher-overview.adoc index 59496ed94..df03ff216 100644 --- a/modules/ROOT/pages/introduction/cypher-overview.adoc +++ b/modules/ROOT/pages/introduction/cypher-overview.adoc @@ -36,7 +36,7 @@ However, there are some important differences between the two: *Cypher is schema-flexible*:: While it is both possible and advised to enforce partial schemas using xref:constraints/index.adoc[indexes and constraints], Cypher and Neo4j offers a greater degree of schema-flexibility than SQL and a relational database. -More specifically, nodes and relationships in a Neo4j database do not have to have a specific property set to them because other nodes or relationships in the same graph have that property (unless there is an xref:constraints/managing-constraints.adoc#create-property-existence-constraints[property existence constraint] created on that specific property). +More specifically, nodes and relationships in a Neo4j database do not have to have a specific property set to them because other nodes or relationships in the same graph have that property (unless there is an xref:constraints/create-constraints.adoc#create-property-existence-constraints[property existence constraint] created on that specific property). This means that users are not required to use a fixed schema to represent data and that they can add new attributes and relationships as their graphs evolve. *Query order*:: diff --git a/modules/ROOT/pages/patterns/shortest-paths.adoc b/modules/ROOT/pages/patterns/shortest-paths.adoc index cffb3cd68..6c8e89b7c 100644 --- a/modules/ROOT/pages/patterns/shortest-paths.adoc +++ b/modules/ROOT/pages/patterns/shortest-paths.adoc @@ -671,7 +671,7 @@ ready to start consuming query after 4 ms, results consumed after another 106 ms [[single-source-target-pair-index]] === Enforcing a single source-target node pair with indexes and constraints -Another way to inform the planner of the uniqueness of the target node in a shortest path is to create an xref:indexes/search-performance-indexes/index.adoc[index] or xref:constraints/managing-constraints.adoc#create-property-uniqueness-constraints[property uniqueness]/xref:constraints/managing-constraints.adoc#create-key-constraints[key constraint] (both of which are xref:constraints/managing-constraints.adoc#constraints-and-backing-indexes[index-backed]) on a property belonging to the matched nodes in the shortest path. +Another way to inform the planner of the uniqueness of the target node in a shortest path is to create an xref:indexes/search-performance-indexes/index.adoc[index] or xref:constraints/create-constraints.adoc#create-property-uniqueness-constraints[property uniqueness]/xref:constraints/create-constraints.adoc#create-key-constraints[key constraint] (both of which are xref:constraints/create-constraints.adoc#constraints-and-backing-indexes[index-backed]) on a property belonging to the matched nodes in the shortest path. This will accurately inform the planner of node cardinality and thereby enable more efficient query planning (assuming the graph contains uniquely identifying node properties). .Impact of indexes and constraints diff --git a/modules/ROOT/pages/planning-and-tuning/operators/operators-detail.adoc b/modules/ROOT/pages/planning-and-tuning/operators/operators-detail.adoc index 30e9edece..0fa51ab5f 100644 --- a/modules/ROOT/pages/planning-and-tuning/operators/operators-detail.adoc +++ b/modules/ROOT/pages/planning-and-tuning/operators/operators-detail.adoc @@ -805,7 +805,7 @@ Total database accesses: 3, total allocated memory: 312 The `NodeIndexSeek` operator finds nodes using an index seek. The node variable and the index used are shown in the arguments of the operator. -If the index is backs up a xref:constraints/managing-constraints.adoc#create-property-uniqueness-constraints[property uniqueness constraint], the operator is instead called xref::planning-and-tuning/operators/operators-detail.adoc#query-plan-node-unique-index-seek[NodeUniqueIndexSeek]. +If the index is backs up a xref:constraints/create-constraints.adoc#create-property-uniqueness-constraints[property uniqueness constraint], the operator is instead called xref::planning-and-tuning/operators/operators-detail.adoc#query-plan-node-unique-index-seek[NodeUniqueIndexSeek]. .NodeIndexSeek @@ -897,7 +897,7 @@ CREATE CONSTRAINT team_name IF NOT EXISTS FOR (t:Team) REQUIRE (t.name) IS UNIQU ---- //// -The `NodeUniqueIndexSeek` operator finds nodes using an index seek within an index backing up a xref:constraints/managing-constraints.adoc#create-property-uniqueness-constraints[property uniqueness constraint]. +The `NodeUniqueIndexSeek` operator finds nodes using an index seek within an index backing up a xref:constraints/create-constraints.adoc#create-property-uniqueness-constraints[property uniqueness constraint]. The node variable and the index used are shown in the arguments of the operator. If the index does not back up a property uniqueness constraint, the operator is instead called xref::planning-and-tuning/operators/operators-detail.adoc#query-plan-node-index-seek[NodeIndexSeek]. If the index seek is used to solve a xref::clauses/merge.adoc[MERGE] clause, it will also be marked with `(Locking)`. @@ -1008,7 +1008,7 @@ CREATE CONSTRAINT team_id IF NOT EXISTS FOR (t:Team) REQUIRE (t.id) IS UNIQUE ---- //// -The `AssertingMultiNodeIndexSeek` operator is used to ensure that no xref:constraints/managing-constraints.adoc#create-property-uniqueness-constraints[property uniqueness constraints] are violated. +The `AssertingMultiNodeIndexSeek` operator is used to ensure that no xref:constraints/create-constraints.adoc#create-property-uniqueness-constraints[property uniqueness constraints] are violated. The example looks for the presence of a team with the supplied name and id, and if one does not exist, it will be created. Owing to the existence of two property uniqueness constraints on `:Team(name)` and `:Team(id)`, any node that would be found by the `UniqueIndexSeek` operator must be the very same node or the constraints would be violated. diff --git a/modules/ROOT/pages/values-and-types/property-structural-constructed.adoc b/modules/ROOT/pages/values-and-types/property-structural-constructed.adoc index a64d72745..de92fcbf4 100644 --- a/modules/ROOT/pages/values-and-types/property-structural-constructed.adoc +++ b/modules/ROOT/pages/values-and-types/property-structural-constructed.adoc @@ -74,7 +74,7 @@ For more details, see xref::values-and-types/working-with-null.adoc[working with The table below shows the types and their syntactic synonyms. -These types (and their synonyms) can be used in xref::expressions/predicates/type-predicate-expressions.adoc[type predicate expressions] and in xref::constraints/managing-constraints.adoc#create-property-type-constraints[property type constraints]. +These types (and their synonyms) can be used in xref::expressions/predicates/type-predicate-expressions.adoc[type predicate expressions] and in xref::constraints/create-constraints.adoc#create-property-type-constraints[property type constraints]. They are also returned as a `STRING` value when using the xref::functions/scalar.adoc#functions-valueType[valueType()] function. However, not all types can be used in all places. @@ -121,7 +121,7 @@ The type `PROPERTY VALUE` is expanded to a closed dynamic union of all valid pro For example, given the closed dynamic type `BOOL | LIST | BOOLEAN | LIST`, the normalized type would be: `BOOLEAN | LIST`. -This normalization is run on types used in xref::expressions/predicates/type-predicate-expressions.adoc[type predicate expressions], and in xref::constraints/managing-constraints.adoc#create-property-type-constraints[property type constraints]. +This normalization is run on types used in xref::expressions/predicates/type-predicate-expressions.adoc[type predicate expressions], and in xref::constraints/create-constraints.adoc#create-property-type-constraints[property type constraints]. Type normalization is also used to ensure the consistency of the output for the xref::functions/scalar.adoc#functions-valueType[valueType()] function. [[ordering-of-types]]